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

Public Instance methods

additional_form_tags(name=feature_name)
[show source]
    # File lib/rodauth.rb
282 def additional_form_tags(name=feature_name)
283   auth_value_method(:"#{name}_additional_form_tags", nil)
284 end
auth_cached_method(meth, iv=:"@#{meth}")
[show source]
    # File lib/rodauth.rb
306 def auth_cached_method(meth, iv=:"@#{meth}")
307   umeth = :"_#{meth}"
308   define_method(meth) do
309     if instance_variable_defined?(iv)
310       instance_variable_get(iv)
311     else
312       instance_variable_set(iv, send(umeth))
313     end
314   end
315   alias_method(meth, meth)
316   auth_private_methods(meth)
317 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
296 def auth_value_method(meth, value)
297   define_method(meth){value}
298   auth_value_methods(meth)
299 end
configuration_module_eval(&block)
[show source]
    # File lib/rodauth.rb
176 def configuration_module_eval(&block)
177   configuration.module_eval(&block)
178 end
def_deprecated_alias(new, old)
[show source]
    # File lib/rodauth.rb
187 def def_deprecated_alias(new, old)
188   configuration_module_eval do
189     define_method(old) do |*a, &block|
190       warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS)
191       send(new, *a, &block)
192     end
193   end
194   define_method(old) do
195     warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS)
196     send(new)
197   end
198 end
depends(*deps)
[show source]
    # File lib/rodauth.rb
241 def depends(*deps)
242   dependencies.concat(deps)
243 end
email(type, subject, opts = {})
[show source]
    # File lib/rodauth.rb
255 def email(type, subject, opts = {})
256   subject_method = :"#{type}_email_subject"
257   body_method = :"#{type}_email_body"
258   create_method = :"create_#{type}_email"
259   send_method = :"send_#{type}_email"
260 
261   translatable_method subject_method, subject
262   auth_methods create_method, send_method
263 
264   body_template = "#{type.to_s.tr('_', '-')}-email"
265   if opts[:translatable]
266     auth_value_methods body_method
267     define_method(body_method){translate(body_method, render(body_template))}
268   else
269     auth_methods body_method
270     define_method(body_method){render(body_template)}
271   end
272 
273   define_method(create_method) do
274     create_email(send(subject_method), send(body_method))
275   end
276 
277   define_method(send_method) do
278     send_email(send(create_method))
279   end
280 end
flash_key(meth, value)
[show source]
    # File lib/rodauth.rb
291 def flash_key(meth, value)
292   define_method(meth){normalize_session_or_flash_key(value)}
293   auth_value_methods(meth)
294 end
internal_request_method(name=feature_name)
[show source]
    # File lib/rodauth.rb
172 def internal_request_method(name=feature_name)
173   (@internal_request_methods ||= []) << name
174 end
loaded_templates(v)
[show source]
    # File lib/rodauth.rb
234 def loaded_templates(v)
235   define_method(:loaded_templates) do
236     super().concat(v)
237   end
238   private :loaded_templates
239 end
redirect(name=feature_name, &block)
[show source]
    # File lib/rodauth.rb
201 def redirect(name=feature_name, &block)
202   meth = :"#{name}_redirect"
203   block ||= DEFAULT_REDIRECT_BLOCK
204   define_method(meth, &block)
205   auth_value_methods meth
206 end
response(name=feature_name)
[show source]
    # File lib/rodauth.rb
218 def response(name=feature_name)
219   meth = :"#{name}_response"
220   overridable_meth = :"_#{meth}"
221   notice_flash_meth = :"#{name}_notice_flash"
222   redirect_meth = :"#{name}_redirect"
223   define_method(overridable_meth) do
224     set_notice_flash send(notice_flash_meth)
225     redirect send(redirect_meth)
226   end
227   define_method(meth) do
228     require_response(overridable_meth)
229   end
230   private overridable_meth, meth
231   auth_private_methods meth
232 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       @current_route = name
142       check_csrf if check_csrf?
143       _around_rodauth do
144         before_rodauth
145         send(internal_handle_meth, request)
146       end
147     end
148   end
149 
150   routes << handle_meth
151 end
session_key(meth, value)
[show source]
    # File lib/rodauth.rb
286 def session_key(meth, value)
287   define_method(meth){convert_session_key(value)}
288   auth_value_methods(meth)
289 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
301 def translatable_method(meth, value)
302   define_method(meth){translate(meth, value)}
303   auth_value_methods(meth)
304 end
view(page, title, name=feature_name)
[show source]
    # File lib/rodauth.rb
208 def view(page, title, name=feature_name)
209   meth = :"#{name}_view"
210   title_meth = :"#{name}_page_title"
211   translatable_method(title_meth, title)
212   define_method(meth) do
213     view(page, send(title_meth))
214   end
215   auth_methods meth
216 end