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

Public Instance methods

additional_form_tags(name=feature_name)
[show source]
    # File lib/rodauth.rb
263 def additional_form_tags(name=feature_name)
264   auth_value_method(:"#{name}_additional_form_tags", nil)
265 end
auth_cached_method(meth, iv=:"@#{meth}")
[show source]
    # File lib/rodauth.rb
282 def auth_cached_method(meth, iv=:"@#{meth}")
283   umeth = :"_#{meth}"
284   define_method(meth) do
285     if instance_variable_defined?(iv)
286       instance_variable_get(iv)
287     else
288       instance_variable_set(iv, send(umeth))
289     end
290   end
291   alias_method(meth, meth)
292   auth_private_methods(meth)
293 end
auth_value_method(meth, value)
[show source]
    # File lib/rodauth.rb
272 def auth_value_method(meth, value)
273   define_method(meth){value}
274   auth_value_methods(meth)
275 end
configuration_module_eval(&block)
[show source]
    # File lib/rodauth.rb
173 def configuration_module_eval(&block)
174   configuration.module_eval(&block)
175 end
def_deprecated_alias(new, old)
[show source]
    # File lib/rodauth.rb
184 def def_deprecated_alias(new, old)
185   configuration_module_eval do
186     define_method(old) do |*a, &block|
187       warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS)
188       send(new, *a, &block)
189     end
190   end
191   define_method(old) do
192     warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS)
193     send(new)
194   end
195 end
depends(*deps)
[show source]
    # File lib/rodauth.rb
222 def depends(*deps)
223   dependencies.concat(deps)
224 end
email(type, subject, opts = {})
[show source]
    # File lib/rodauth.rb
236 def email(type, subject, opts = {})
237   subject_method = :"#{type}_email_subject"
238   body_method = :"#{type}_email_body"
239   create_method = :"create_#{type}_email"
240   send_method = :"send_#{type}_email"
241 
242   translatable_method subject_method, subject
243   auth_methods create_method, send_method
244 
245   body_template = "#{type.to_s.tr('_', '-')}-email"
246   if opts[:translatable]
247     auth_value_methods body_method
248     define_method(body_method){translate(body_method, render(body_template))}
249   else
250     auth_methods body_method
251     define_method(body_method){render(body_template)}
252   end
253 
254   define_method(create_method) do
255     create_email(send(subject_method), send(body_method))
256   end
257 
258   define_method(send_method) do
259     send_email(send(create_method))
260   end
261 end
internal_request_method(name=feature_name)
[show source]
    # File lib/rodauth.rb
169 def internal_request_method(name=feature_name)
170   (@internal_request_methods ||= []) << name
171 end
loaded_templates(v)
[show source]
    # File lib/rodauth.rb
215 def loaded_templates(v)
216   define_method(:loaded_templates) do
217     super().concat(v)
218   end
219   private :loaded_templates
220 end
redirect(name=feature_name, &block)
[show source]
    # File lib/rodauth.rb
198 def redirect(name=feature_name, &block)
199   meth = :"#{name}_redirect"
200   block ||= DEFAULT_REDIRECT_BLOCK
201   define_method(meth, &block)
202   auth_value_methods meth
203 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
    # File lib/rodauth.rb
125 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
126   route_meth = :"#{name}_route"
127   auth_value_method route_meth, default
128 
129   define_method(:"#{name}_path"){|opts={}| route_path(send(route_meth), opts)}
130   define_method(:"#{name}_url"){|opts={}| route_url(send(route_meth), opts)}
131 
132   handle_meth = :"handle_#{name}"
133   internal_handle_meth = :"_#{handle_meth}"
134   before route_meth
135   define_method(internal_handle_meth, &block)
136 
137   define_method(handle_meth) do
138     request.is send(route_meth) do
139       check_csrf if check_csrf?
140       _around_rodauth do
141         before_rodauth
142         send(internal_handle_meth, request)
143       end
144     end
145   end
146 
147   routes << handle_meth
148 end
session_key(meth, value)
[show source]
    # File lib/rodauth.rb
267 def session_key(meth, value)
268   define_method(meth){convert_session_key(value)}
269   auth_value_methods(meth)
270 end
translatable_method(meth, value)
[show source]
    # File lib/rodauth.rb
277 def translatable_method(meth, value)
278   define_method(meth){translate(meth, value)}
279   auth_value_methods(meth)
280 end
view(page, title, name=feature_name)
[show source]
    # File lib/rodauth.rb
205 def view(page, title, name=feature_name)
206   meth = :"#{name}_view"
207   title_meth = :"#{name}_page_title"
208   translatable_method(title_meth, title)
209   define_method(meth) do
210     view(page, send(title_meth))
211   end
212   auth_methods meth
213 end