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
178 def self.define(name, constant=nil, &block)
179   feature = new
180   feature.dependencies = []
181   feature.routes = []
182   feature.feature_name = name
183   configuration = feature.configuration = FeatureConfiguration.new
184   feature.module_eval(&block)
185   configuration.def_configuration_methods(feature)
186 
187   # :nocov:
188   if constant
189   # :nocov:
190     Rodauth.const_set(constant, feature)
191     Rodauth::FeatureConfiguration.const_set(constant, configuration)
192   end
193 
194   FEATURES[name] = feature
195 end

Public Instance methods

additional_form_tags(name=feature_name)
[show source]
    # File lib/rodauth.rb
311 def additional_form_tags(name=feature_name)
312   auth_value_method(:"#{name}_additional_form_tags", nil)
313 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
325 def auth_value_method(meth, value)
326   define_method(meth){value}
327   auth_value_methods(meth)
328 end
cached_auth_method(meth, iv=:"@#{meth}")

Auth caching method that treats a nil instance variable as not being cached. If nil is a valid value for the instance variable, do not use this method, use a regular auth_method and handle caching manually.

[show source]
    # File lib/rodauth.rb
339 def cached_auth_method(meth, iv=:"@#{meth}")
340   umeth = :"_#{meth}"
341   define_method(meth) do
342     v = instance_variable_get(iv)
343     v.nil? ? instance_variable_set(iv, send(umeth)) : v
344   end
345   alias_method(meth, meth)
346   auth_private_methods(meth)
347 end
configuration_module_eval(&block)
[show source]
    # File lib/rodauth.rb
205 def configuration_module_eval(&block)
206   configuration.module_eval(&block)
207 end
def_deprecated_alias(new, old)
[show source]
    # File lib/rodauth.rb
216 def def_deprecated_alias(new, old)
217   configuration_module_eval do
218     define_method(old) do |*a, &block|
219       warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS)
220       send(new, *a, &block)
221     end
222   end
223   define_method(old) do
224     warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS)
225     send(new)
226   end
227 end
depends(*deps)
[show source]
    # File lib/rodauth.rb
270 def depends(*deps)
271   dependencies.concat(deps)
272 end
email(type, subject, opts = OPTS)
[show source]
    # File lib/rodauth.rb
284 def email(type, subject, opts = OPTS)
285   subject_method = :"#{type}_email_subject"
286   body_method = :"#{type}_email_body"
287   create_method = :"create_#{type}_email"
288   send_method = :"send_#{type}_email"
289 
290   translatable_method subject_method, subject
291   auth_methods create_method, send_method
292 
293   body_template = "#{type.to_s.tr('_', '-')}-email"
294   if opts[:translatable]
295     auth_value_methods body_method
296     define_method(body_method){translate(body_method, render(body_template))}
297   else
298     auth_methods body_method
299     define_method(body_method){render(body_template)}
300   end
301 
302   define_method(create_method) do
303     create_email(send(subject_method), send(body_method))
304   end
305 
306   define_method(send_method) do
307     send_email(send(create_method))
308   end
309 end
flash_key(meth, value)
[show source]
    # File lib/rodauth.rb
320 def flash_key(meth, value)
321   define_method(meth){normalize_session_or_flash_key(value)}
322   auth_value_methods(meth)
323 end
internal_request_method(name=feature_name)
[show source]
    # File lib/rodauth.rb
197 def internal_request_method(name=feature_name)
198   (@internal_request_methods ||= []) << name
199 end
loaded_templates(v)
[show source]
    # File lib/rodauth.rb
263 def loaded_templates(v)
264   define_method(:loaded_templates) do
265     super().concat(v)
266   end
267   private :loaded_templates
268 end
redirect(name=feature_name, &block)
[show source]
    # File lib/rodauth.rb
230 def redirect(name=feature_name, &block)
231   meth = :"#{name}_redirect"
232   block ||= DEFAULT_REDIRECT_BLOCK
233   define_method(meth, &block)
234   auth_value_methods meth
235 end
response(name=feature_name)
[show source]
    # File lib/rodauth.rb
247 def response(name=feature_name)
248   meth = :"#{name}_response"
249   overridable_meth = :"_#{meth}"
250   notice_flash_meth = :"#{name}_notice_flash"
251   redirect_meth = :"#{name}_redirect"
252   define_method(overridable_meth) do
253     set_notice_flash send(notice_flash_meth)
254     redirect send(redirect_meth)
255   end
256   define_method(meth) do
257     require_response(overridable_meth)
258   end
259   private overridable_meth, meth
260   auth_private_methods meth
261 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
    # File lib/rodauth.rb
152 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
153   route_meth = :"#{name}_route"
154   auth_value_method route_meth, default
155 
156   define_method(:"#{name}_path"){|opts=OPTS| route_path(send(route_meth), opts) if send(route_meth)}
157   define_method(:"#{name}_url"){|opts=OPTS| route_url(send(route_meth), opts) if send(route_meth)}
158 
159   handle_meth = :"handle_#{name}"
160   internal_handle_meth = :"_#{handle_meth}"
161   before route_meth
162   define_method(internal_handle_meth, &block)
163 
164   define_method(handle_meth) do
165     request.is send(route_meth) do
166       @current_route = name
167       check_csrf if check_csrf?
168       _around_rodauth do
169         before_rodauth
170         send(internal_handle_meth, request)
171       end
172     end
173   end
174 
175   routes << handle_meth
176 end
session_key(meth, value)
[show source]
    # File lib/rodauth.rb
315 def session_key(meth, value)
316   define_method(meth){convert_session_key(value)}
317   auth_value_methods(meth)
318 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
330 def translatable_method(meth, value)
331   define_method(meth){translate(meth, value)}
332   auth_value_methods(meth)
333 end
uses_instance_variables(*ivs)
[show source]
    # File lib/rodauth.rb
201 def uses_instance_variables(*ivs)
202   @instance_variables_used = ivs.freeze
203 end
view(page, title, name=feature_name)
[show source]
    # File lib/rodauth.rb
237 def view(page, title, name=feature_name)
238   meth = :"#{name}_view"
239   title_meth = :"#{name}_page_title"
240   translatable_method(title_meth, title)
241   define_method(meth) do
242     view(page, send(title_meth))
243   end
244   auth_methods meth
245 end