Class: Rodauth::Feature
- Inherits:
-
Module
- Object
- Module
- Rodauth::Feature
- Defined in:
- lib/rodauth.rb
Constant Summary collapse
- DEFAULT_REDIRECT_BLOCK =
proc{default_redirect}
Instance Attribute Summary collapse
-
#configuration ⇒ Object
Returns the value of attribute configuration.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#feature_name ⇒ Object
Returns the value of attribute feature_name.
-
#routes ⇒ Object
Returns the value of attribute routes.
Class Method Summary collapse
Instance Method Summary collapse
- #additional_form_tags(name = feature_name) ⇒ Object
- #auth_cached_method(meth, iv = :"@#{meth}") ⇒ Object
- #auth_value_method(meth, value) ⇒ Object
- #configuration_module_eval(&block) ⇒ Object
- #depends(*deps) ⇒ Object
- #redirect(name = feature_name, &block) ⇒ Object
- #route(name = feature_name, default = name.to_s.tr('_', '-'), &block) ⇒ Object
- #view(page, title, name = feature_name) ⇒ Object
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
80 81 82 |
# File 'lib/rodauth.rb', line 80 def configuration @configuration end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
78 79 80 |
# File 'lib/rodauth.rb', line 78 def dependencies @dependencies end |
#feature_name ⇒ Object
Returns the value of attribute feature_name.
77 78 79 |
# File 'lib/rodauth.rb', line 77 def feature_name @feature_name end |
#routes ⇒ Object
Returns the value of attribute routes.
79 80 81 |
# File 'lib/rodauth.rb', line 79 def routes @routes end |
Class Method Details
.define(name, &block) ⇒ Object
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/rodauth.rb', line 99 def self.define(name, &block) feature = new feature.dependencies = [] feature.routes = [] feature.feature_name = name configuration = feature.configuration = FeatureConfiguration.new feature.module_eval(&block) configuration.def_configuration_methods(feature) FEATURES[name] = feature end |
Instance Method Details
#additional_form_tags(name = feature_name) ⇒ Object
145 146 147 |
# File 'lib/rodauth.rb', line 145 def (name=feature_name) auth_value_method(:"#{name}_additional_form_tags", nil) end |
#auth_cached_method(meth, iv = :"@#{meth}") ⇒ Object
154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/rodauth.rb', line 154 def auth_cached_method(meth, iv=:"@#{meth}") umeth = :"_#{meth}" define_method(meth) do if instance_variable_defined?(iv) instance_variable_get(iv) else instance_variable_set(iv, send(umeth)) end end auth_private_methods(meth) end |
#auth_value_method(meth, value) ⇒ Object
149 150 151 152 |
# File 'lib/rodauth.rb', line 149 def auth_value_method(meth, value) define_method(meth){value} auth_value_methods(meth) end |
#configuration_module_eval(&block) ⇒ Object
110 111 112 |
# File 'lib/rodauth.rb', line 110 def configuration_module_eval(&block) configuration.module_eval(&block) end |
#depends(*deps) ⇒ Object
130 131 132 |
# File 'lib/rodauth.rb', line 130 def depends(*deps) dependencies.concat(deps) end |
#redirect(name = feature_name, &block) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/rodauth.rb', line 115 def redirect(name=feature_name, &block) meth = :"#{name}_redirect" block ||= DEFAULT_REDIRECT_BLOCK define_method(meth, &block) auth_value_methods meth end |
#route(name = feature_name, default = name.to_s.tr('_', '-'), &block) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/rodauth.rb', line 82 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block) auth_value_method "#{name}_route", default handle_meth = "handle_#{name}" route_meth = :"#{name}_route" before route_meth define_method(handle_meth) do request.is send(route_meth) do before_rodauth instance_exec(request, &block) end end routes << handle_meth end |
#view(page, title, name = feature_name) ⇒ Object
122 123 124 125 126 127 128 |
# File 'lib/rodauth.rb', line 122 def view(page, title, name=feature_name) meth = :"#{name}_view" define_method(meth) do view(page, title) end auth_methods meth end |