Methods
Public Class
Public Instance
- additional_form_tags
- auth_value_method
- cached_auth_method
- configuration
- configuration_module_eval
- def_deprecated_alias
- dependencies
- depends
- feature_name
- flash_key
- instance_variables_used
- internal_request_method
- internal_request_methods
- loaded_templates
- redirect
- response
- route
- routes
- session_key
- translatable_method
- uses_instance_variables
- view
Constants
| DEFAULT_REDIRECT_BLOCK | = | proc{default_redirect} | ||
| DEPRECATED_ARGS | = | [{:uplevel=>1}] |
:nocov: |
Attributes
| configuration | [RW] | |
| dependencies | [RW] | |
| feature_name | [RW] | |
| instance_variables_used | [R] | |
| internal_request_methods | [R] | |
| routes | [RW] |
Public Class methods
define(name, constant=nil, &block)
[show source]
# File lib/rodauth.rb 157 def self.define(name, constant=nil, &block) 158 feature = new 159 feature.dependencies = [] 160 feature.routes = [] 161 feature.feature_name = name 162 configuration = feature.configuration = FeatureConfiguration.new 163 feature.module_eval(&block) 164 configuration.def_configuration_methods(feature) 165 166 # :nocov: 167 if constant 168 # :nocov: 169 Rodauth.const_set(constant, feature) 170 Rodauth::FeatureConfiguration.const_set(constant, configuration) 171 end 172 173 FEATURES[name] = feature 174 end
Public Instance methods
additional_form_tags(name=feature_name)
[show source]
# File lib/rodauth.rb 290 def additional_form_tags(name=feature_name) 291 auth_value_method(:"#{name}_additional_form_tags", nil) 292 end
auth_value_method(meth, value)
[show source]
# File lib/rodauth.rb 304 def auth_value_method(meth, value) 305 define_method(meth){value} 306 auth_value_methods(meth) 307 end
cached_auth_method(meth, iv=:"@#{meth}")
Auth caching method that treats a nil instance variable as not being cached. If nil is a valid value for the instance variable, do not use this method, use a regular auth_method and handle caching manually.
[show source]
# File lib/rodauth.rb 318 def cached_auth_method(meth, iv=:"@#{meth}") 319 umeth = :"_#{meth}" 320 define_method(meth) do 321 v = instance_variable_get(iv) 322 v.nil? ? instance_variable_set(iv, send(umeth)) : v 323 end 324 alias_method(meth, meth) 325 auth_private_methods(meth) 326 end
configuration_module_eval(&block)
[show source]
# File lib/rodauth.rb 184 def configuration_module_eval(&block) 185 configuration.module_eval(&block) 186 end
def_deprecated_alias(new, old)
[show source]
# File lib/rodauth.rb 195 def def_deprecated_alias(new, old) 196 configuration_module_eval do 197 define_method(old) do |*a, &block| 198 warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS) 199 send(new, *a, &block) 200 end 201 end 202 define_method(old) do 203 warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS) 204 send(new) 205 end 206 end
depends(*deps)
[show source]
# File lib/rodauth.rb 249 def depends(*deps) 250 dependencies.concat(deps) 251 end
email(type, subject, opts = {})
[show source]
# File lib/rodauth.rb 263 def email(type, subject, opts = {}) 264 subject_method = :"#{type}_email_subject" 265 body_method = :"#{type}_email_body" 266 create_method = :"create_#{type}_email" 267 send_method = :"send_#{type}_email" 268 269 translatable_method subject_method, subject 270 auth_methods create_method, send_method 271 272 body_template = "#{type.to_s.tr('_', '-')}-email" 273 if opts[:translatable] 274 auth_value_methods body_method 275 define_method(body_method){translate(body_method, render(body_template))} 276 else 277 auth_methods body_method 278 define_method(body_method){render(body_template)} 279 end 280 281 define_method(create_method) do 282 create_email(send(subject_method), send(body_method)) 283 end 284 285 define_method(send_method) do 286 send_email(send(create_method)) 287 end 288 end
flash_key(meth, value)
[show source]
# File lib/rodauth.rb 299 def flash_key(meth, value) 300 define_method(meth){normalize_session_or_flash_key(value)} 301 auth_value_methods(meth) 302 end
internal_request_method(name=feature_name)
[show source]
# File lib/rodauth.rb 176 def internal_request_method(name=feature_name) 177 (@internal_request_methods ||= []) << name 178 end
loaded_templates(v)
[show source]
# File lib/rodauth.rb 242 def loaded_templates(v) 243 define_method(:loaded_templates) do 244 super().concat(v) 245 end 246 private :loaded_templates 247 end
redirect(name=feature_name, &block)
[show source]
# File lib/rodauth.rb 209 def redirect(name=feature_name, &block) 210 meth = :"#{name}_redirect" 211 block ||= DEFAULT_REDIRECT_BLOCK 212 define_method(meth, &block) 213 auth_value_methods meth 214 end
response(name=feature_name)
[show source]
# File lib/rodauth.rb 226 def response(name=feature_name) 227 meth = :"#{name}_response" 228 overridable_meth = :"_#{meth}" 229 notice_flash_meth = :"#{name}_notice_flash" 230 redirect_meth = :"#{name}_redirect" 231 define_method(overridable_meth) do 232 set_notice_flash send(notice_flash_meth) 233 redirect send(redirect_meth) 234 end 235 define_method(meth) do 236 require_response(overridable_meth) 237 end 238 private overridable_meth, meth 239 auth_private_methods meth 240 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
# File lib/rodauth.rb 131 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block) 132 route_meth = :"#{name}_route" 133 auth_value_method route_meth, default 134 135 define_method(:"#{name}_path"){|opts={}| route_path(send(route_meth), opts) if send(route_meth)} 136 define_method(:"#{name}_url"){|opts={}| route_url(send(route_meth), opts) if send(route_meth)} 137 138 handle_meth = :"handle_#{name}" 139 internal_handle_meth = :"_#{handle_meth}" 140 before route_meth 141 define_method(internal_handle_meth, &block) 142 143 define_method(handle_meth) do 144 request.is send(route_meth) do 145 @current_route = name 146 check_csrf if check_csrf? 147 _around_rodauth do 148 before_rodauth 149 send(internal_handle_meth, request) 150 end 151 end 152 end 153 154 routes << handle_meth 155 end
session_key(meth, value)
[show source]
# File lib/rodauth.rb 294 def session_key(meth, value) 295 define_method(meth){convert_session_key(value)} 296 auth_value_methods(meth) 297 end
translatable_method(meth, value)
[show source]
# File lib/rodauth.rb 309 def translatable_method(meth, value) 310 define_method(meth){translate(meth, value)} 311 auth_value_methods(meth) 312 end
uses_instance_variables(*ivs)
[show source]
# File lib/rodauth.rb 180 def uses_instance_variables(*ivs) 181 @instance_variables_used = ivs.freeze 182 end
view(page, title, name=feature_name)
[show source]
# File lib/rodauth.rb 216 def view(page, title, name=feature_name) 217 meth = :"#{name}_view" 218 title_meth = :"#{name}_page_title" 219 translatable_method(title_meth, title) 220 define_method(meth) do 221 view(page, send(title_meth)) 222 end 223 auth_methods meth 224 end