class Rodauth::Feature

  1. lib/rodauth.rb
Superclass: Module

Constants

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

simplecov:disable

Public Class methods

define(name, constant=nil, &block)
[show source]
    # File lib/rodauth.rb
182 def self.define(name, constant=nil, &block)
183   feature = new
184   feature.dependencies = []
185   feature.routes = []
186   feature.feature_name = name
187   configuration = feature.configuration = FeatureConfiguration.new
188   feature.module_eval(&block)
189   configuration.def_configuration_methods(feature)
190 
191   # simplecov:disable
192   if constant
193   # simplecov:enable
194     Rodauth.const_set(constant, feature)
195     Rodauth::FeatureConfiguration.const_set(constant, configuration)
196   end
197 
198   FEATURES[name] = feature
199 end

Public Instance methods

additional_form_tags(name=feature_name)
[show source]
    # File lib/rodauth.rb
315 def additional_form_tags(name=feature_name)
316   auth_value_method(:"#{name}_additional_form_tags", nil)
317 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
329 def auth_value_method(meth, value)
330   define_method(meth){value}
331   auth_value_methods(meth)
332 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
343 def cached_auth_method(meth, iv=:"@#{meth}")
344   umeth = :"_#{meth}"
345   define_method(meth) do
346     v = instance_variable_get(iv)
347     v.nil? ? instance_variable_set(iv, send(umeth)) : v
348   end
349   alias_method(meth, meth)
350   auth_private_methods(meth)
351 end
configuration_module_eval(&block)
[show source]
    # File lib/rodauth.rb
209 def configuration_module_eval(&block)
210   configuration.module_eval(&block)
211 end
def_deprecated_alias(new, old)
[show source]
    # File lib/rodauth.rb
220 def def_deprecated_alias(new, old)
221   configuration_module_eval do
222     define_method(old) do |*a, &block|
223       warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS)
224       send(new, *a, &block)
225     end
226   end
227   define_method(old) do
228     warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS)
229     send(new)
230   end
231 end
depends(*deps)
[show source]
    # File lib/rodauth.rb
274 def depends(*deps)
275   dependencies.concat(deps)
276 end
email(type, subject, opts = OPTS)
[show source]
    # File lib/rodauth.rb
288 def email(type, subject, opts = OPTS)
289   subject_method = :"#{type}_email_subject"
290   body_method = :"#{type}_email_body"
291   create_method = :"create_#{type}_email"
292   send_method = :"send_#{type}_email"
293 
294   translatable_method subject_method, subject
295   auth_methods create_method, send_method
296 
297   body_template = "#{type.to_s.tr('_', '-')}-email"
298   if opts[:translatable]
299     auth_value_methods body_method
300     define_method(body_method){translate(body_method, render(body_template))}
301   else
302     auth_methods body_method
303     define_method(body_method){render(body_template)}
304   end
305 
306   define_method(create_method) do
307     create_email(send(subject_method), send(body_method))
308   end
309 
310   define_method(send_method) do
311     send_email(send(create_method))
312   end
313 end
flash_key(meth, value)
[show source]
    # File lib/rodauth.rb
324 def flash_key(meth, value)
325   define_method(meth){normalize_session_or_flash_key(value)}
326   auth_value_methods(meth)
327 end
internal_request_method(name=feature_name)
[show source]
    # File lib/rodauth.rb
201 def internal_request_method(name=feature_name)
202   (@internal_request_methods ||= []) << name
203 end
loaded_templates(v)
[show source]
    # File lib/rodauth.rb
267 def loaded_templates(v)
268   define_method(:loaded_templates) do
269     super().concat(v)
270   end
271   private :loaded_templates
272 end
redirect(name=feature_name, &block)
[show source]
    # File lib/rodauth.rb
234 def redirect(name=feature_name, &block)
235   meth = :"#{name}_redirect"
236   block ||= DEFAULT_REDIRECT_BLOCK
237   define_method(meth, &block)
238   auth_value_methods meth
239 end
response(name=feature_name)
[show source]
    # File lib/rodauth.rb
251 def response(name=feature_name)
252   meth = :"#{name}_response"
253   overridable_meth = :"_#{meth}"
254   notice_flash_meth = :"#{name}_notice_flash"
255   redirect_meth = :"#{name}_redirect"
256   define_method(overridable_meth) do
257     set_notice_flash send(notice_flash_meth)
258     redirect send(redirect_meth)
259   end
260   define_method(meth) do
261     require_response(overridable_meth)
262   end
263   private overridable_meth, meth
264   auth_private_methods meth
265 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
    # File lib/rodauth.rb
156 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
157   route_meth = :"#{name}_route"
158   auth_value_method route_meth, default
159 
160   define_method(:"#{name}_path"){|opts=OPTS| route_path(send(route_meth), opts) if send(route_meth)}
161   define_method(:"#{name}_url"){|opts=OPTS| route_url(send(route_meth), opts) if send(route_meth)}
162 
163   handle_meth = :"handle_#{name}"
164   internal_handle_meth = :"_#{handle_meth}"
165   before route_meth
166   define_method(internal_handle_meth, &block)
167 
168   define_method(handle_meth) do
169     request.is send(route_meth) do
170       @current_route = name
171       check_csrf if check_csrf?
172       _around_rodauth do
173         before_rodauth
174         send(internal_handle_meth, request)
175       end
176     end
177   end
178 
179   routes << handle_meth
180 end
session_key(meth, value)
[show source]
    # File lib/rodauth.rb
319 def session_key(meth, value)
320   define_method(meth){convert_session_key(value)}
321   auth_value_methods(meth)
322 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
334 def translatable_method(meth, value)
335   define_method(meth){translate(meth, value)}
336   auth_value_methods(meth)
337 end
uses_instance_variables(*ivs)
[show source]
    # File lib/rodauth.rb
205 def uses_instance_variables(*ivs)
206   @instance_variables_used = ivs.freeze
207 end
view(page, title, name=feature_name)
[show source]
    # File lib/rodauth.rb
241 def view(page, title, name=feature_name)
242   meth = :"#{name}_view"
243   title_meth = :"#{name}_page_title"
244   translatable_method(title_meth, title)
245   define_method(meth) do
246     view(page, send(title_meth))
247   end
248   auth_methods meth
249 end