class Rodauth::Feature

  1. lib/rodauth.rb
Superclass: Module

Constants

DEFAULT_REDIRECT_BLOCK = proc{default_redirect}  
DEPRECATED_ARGS = [{:uplevel=>1}]  

:nocov:

Public Class methods

define(name, constant=nil, &block)
[show source]
    # File lib/rodauth.rb
152 def self.define(name, constant=nil, &block)
153   feature = new
154   feature.dependencies = []
155   feature.routes = []
156   feature.feature_name = name
157   configuration = feature.configuration = FeatureConfiguration.new
158   feature.module_eval(&block)
159   configuration.def_configuration_methods(feature)
160 
161   # :nocov:
162   if constant
163   # :nocov:
164     Rodauth.const_set(constant, feature)
165     Rodauth::FeatureConfiguration.const_set(constant, configuration)
166   end
167 
168   FEATURES[name] = feature
169 end

Public Instance methods

additional_form_tags(name=feature_name)
[show source]
    # File lib/rodauth.rb
281 def additional_form_tags(name=feature_name)
282   auth_value_method(:"#{name}_additional_form_tags", nil)
283 end
auth_cached_method(meth, iv=:"@#{meth}")
[show source]
    # File lib/rodauth.rb
305 def auth_cached_method(meth, iv=:"@#{meth}")
306   umeth = :"_#{meth}"
307   define_method(meth) do
308     if instance_variable_defined?(iv)
309       instance_variable_get(iv)
310     else
311       instance_variable_set(iv, send(umeth))
312     end
313   end
314   alias_method(meth, meth)
315   auth_private_methods(meth)
316 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
295 def auth_value_method(meth, value)
296   define_method(meth){value}
297   auth_value_methods(meth)
298 end
configuration_module_eval(&block)
[show source]
    # File lib/rodauth.rb
175 def configuration_module_eval(&block)
176   configuration.module_eval(&block)
177 end
def_deprecated_alias(new, old)
[show source]
    # File lib/rodauth.rb
186 def def_deprecated_alias(new, old)
187   configuration_module_eval do
188     define_method(old) do |*a, &block|
189       warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS)
190       send(new, *a, &block)
191     end
192   end
193   define_method(old) do
194     warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS)
195     send(new)
196   end
197 end
depends(*deps)
[show source]
    # File lib/rodauth.rb
240 def depends(*deps)
241   dependencies.concat(deps)
242 end
email(type, subject, opts = {})
[show source]
    # File lib/rodauth.rb
254 def email(type, subject, opts = {})
255   subject_method = :"#{type}_email_subject"
256   body_method = :"#{type}_email_body"
257   create_method = :"create_#{type}_email"
258   send_method = :"send_#{type}_email"
259 
260   translatable_method subject_method, subject
261   auth_methods create_method, send_method
262 
263   body_template = "#{type.to_s.tr('_', '-')}-email"
264   if opts[:translatable]
265     auth_value_methods body_method
266     define_method(body_method){translate(body_method, render(body_template))}
267   else
268     auth_methods body_method
269     define_method(body_method){render(body_template)}
270   end
271 
272   define_method(create_method) do
273     create_email(send(subject_method), send(body_method))
274   end
275 
276   define_method(send_method) do
277     send_email(send(create_method))
278   end
279 end
flash_key(meth, value)
[show source]
    # File lib/rodauth.rb
290 def flash_key(meth, value)
291   define_method(meth){normalize_session_or_flash_key(value)}
292   auth_value_methods(meth)
293 end
internal_request_method(name=feature_name)
[show source]
    # File lib/rodauth.rb
171 def internal_request_method(name=feature_name)
172   (@internal_request_methods ||= []) << name
173 end
loaded_templates(v)
[show source]
    # File lib/rodauth.rb
233 def loaded_templates(v)
234   define_method(:loaded_templates) do
235     super().concat(v)
236   end
237   private :loaded_templates
238 end
redirect(name=feature_name, &block)
[show source]
    # File lib/rodauth.rb
200 def redirect(name=feature_name, &block)
201   meth = :"#{name}_redirect"
202   block ||= DEFAULT_REDIRECT_BLOCK
203   define_method(meth, &block)
204   auth_value_methods meth
205 end
response(name=feature_name)
[show source]
    # File lib/rodauth.rb
217 def response(name=feature_name)
218   meth = :"#{name}_response"
219   overridable_meth = :"_#{meth}"
220   notice_flash_meth = :"#{name}_notice_flash"
221   redirect_meth = :"#{name}_redirect"
222   define_method(overridable_meth) do
223     set_notice_flash send(notice_flash_meth)
224     redirect send(redirect_meth)
225   end
226   define_method(meth) do
227     require_response(overridable_meth)
228   end
229   private overridable_meth, meth
230   auth_private_methods meth
231 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
    # File lib/rodauth.rb
127 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
128   route_meth = :"#{name}_route"
129   auth_value_method route_meth, default
130 
131   define_method(:"#{name}_path"){|opts={}| route_path(send(route_meth), opts) if send(route_meth)}
132   define_method(:"#{name}_url"){|opts={}| route_url(send(route_meth), opts) if send(route_meth)}
133 
134   handle_meth = :"handle_#{name}"
135   internal_handle_meth = :"_#{handle_meth}"
136   before route_meth
137   define_method(internal_handle_meth, &block)
138 
139   define_method(handle_meth) do
140     request.is send(route_meth) do
141       check_csrf if check_csrf?
142       _around_rodauth do
143         before_rodauth
144         send(internal_handle_meth, request)
145       end
146     end
147   end
148 
149   routes << handle_meth
150 end
session_key(meth, value)
[show source]
    # File lib/rodauth.rb
285 def session_key(meth, value)
286   define_method(meth){convert_session_key(value)}
287   auth_value_methods(meth)
288 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
300 def translatable_method(meth, value)
301   define_method(meth){translate(meth, value)}
302   auth_value_methods(meth)
303 end
view(page, title, name=feature_name)
[show source]
    # File lib/rodauth.rb
207 def view(page, title, name=feature_name)
208   meth = :"#{name}_view"
209   title_meth = :"#{name}_page_title"
210   translatable_method(title_meth, title)
211   define_method(meth) do
212     view(page, send(title_meth))
213   end
214   auth_methods meth
215 end