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
265 def additional_form_tags(name=feature_name)
266   auth_value_method(:"#{name}_additional_form_tags", nil)
267 end
auth_cached_method(meth, iv=:"@#{meth}")
[show source]
    # File lib/rodauth.rb
289 def auth_cached_method(meth, iv=:"@#{meth}")
290   umeth = :"_#{meth}"
291   define_method(meth) do
292     if instance_variable_defined?(iv)
293       instance_variable_get(iv)
294     else
295       instance_variable_set(iv, send(umeth))
296     end
297   end
298   alias_method(meth, meth)
299   auth_private_methods(meth)
300 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
279 def auth_value_method(meth, value)
280   define_method(meth){value}
281   auth_value_methods(meth)
282 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
224 def depends(*deps)
225   dependencies.concat(deps)
226 end
email(type, subject, opts = {})
[show source]
    # File lib/rodauth.rb
238 def email(type, subject, opts = {})
239   subject_method = :"#{type}_email_subject"
240   body_method = :"#{type}_email_body"
241   create_method = :"create_#{type}_email"
242   send_method = :"send_#{type}_email"
243 
244   translatable_method subject_method, subject
245   auth_methods create_method, send_method
246 
247   body_template = "#{type.to_s.tr('_', '-')}-email"
248   if opts[:translatable]
249     auth_value_methods body_method
250     define_method(body_method){translate(body_method, render(body_template))}
251   else
252     auth_methods body_method
253     define_method(body_method){render(body_template)}
254   end
255 
256   define_method(create_method) do
257     create_email(send(subject_method), send(body_method))
258   end
259 
260   define_method(send_method) do
261     send_email(send(create_method))
262   end
263 end
flash_key(meth, value)
[show source]
    # File lib/rodauth.rb
274 def flash_key(meth, value)
275   define_method(meth){normalize_session_or_flash_key(value)}
276   auth_value_methods(meth)
277 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
217 def loaded_templates(v)
218   define_method(:loaded_templates) do
219     super().concat(v)
220   end
221   private :loaded_templates
222 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
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
269 def session_key(meth, value)
270   define_method(meth){convert_session_key(value)}
271   auth_value_methods(meth)
272 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
284 def translatable_method(meth, value)
285   define_method(meth){translate(meth, value)}
286   auth_value_methods(meth)
287 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