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
155 def self.define(name, constant=nil, &block)
156   feature = new
157   feature.dependencies = []
158   feature.routes = []
159   feature.feature_name = name
160   configuration = feature.configuration = FeatureConfiguration.new
161   feature.module_eval(&block)
162   configuration.def_configuration_methods(feature)
163 
164   # :nocov:
165   if constant
166   # :nocov:
167     Rodauth.const_set(constant, feature)
168     Rodauth::FeatureConfiguration.const_set(constant, configuration)
169   end
170 
171   FEATURES[name] = feature
172 end

Public Instance methods

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