Methods
Public Class
Public Instance
- additional_form_tags
- allowed_undefined_configuration_methods
- 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
| allowed_undefined_configuration_methods | [RW] | |
| 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 180 def self.define(name, constant=nil, &block) 181 feature = new 182 feature.dependencies = [] 183 feature.routes = [] 184 feature.feature_name = name 185 configuration = feature.configuration = FeatureConfiguration.new 186 feature.module_eval(&block) 187 configuration.def_configuration_methods(feature) 188 189 # :nocov: 190 if constant 191 # :nocov: 192 Rodauth.const_set(constant, feature) 193 Rodauth::FeatureConfiguration.const_set(constant, configuration) 194 end 195 196 FEATURES[name] = feature 197 end
Public Instance methods
additional_form_tags(name=feature_name)
[show source]
# File lib/rodauth.rb 313 def additional_form_tags(name=feature_name) 314 auth_value_method(:"#{name}_additional_form_tags", nil) 315 end
auth_value_method(meth, value)
[show source]
# File lib/rodauth.rb 327 def auth_value_method(meth, value) 328 define_method(meth){value} 329 auth_value_methods(meth) 330 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 341 def cached_auth_method(meth, iv=:"@#{meth}") 342 umeth = :"_#{meth}" 343 define_method(meth) do 344 v = instance_variable_get(iv) 345 v.nil? ? instance_variable_set(iv, send(umeth)) : v 346 end 347 alias_method(meth, meth) 348 auth_private_methods(meth) 349 end
configuration_module_eval(&block)
[show source]
# File lib/rodauth.rb 207 def configuration_module_eval(&block) 208 configuration.module_eval(&block) 209 end
def_deprecated_alias(new, old)
[show source]
# File lib/rodauth.rb 218 def def_deprecated_alias(new, old) 219 configuration_module_eval do 220 define_method(old) do |*a, &block| 221 warn("Deprecated #{old} method used during configuration, switch to using #{new}", *DEPRECATED_ARGS) 222 send(new, *a, &block) 223 end 224 end 225 define_method(old) do 226 warn("Deprecated #{old} method called at runtime, switch to using #{new}", *DEPRECATED_ARGS) 227 send(new) 228 end 229 end
depends(*deps)
[show source]
# File lib/rodauth.rb 272 def depends(*deps) 273 dependencies.concat(deps) 274 end
email(type, subject, opts = OPTS)
[show source]
# File lib/rodauth.rb 286 def email(type, subject, opts = OPTS) 287 subject_method = :"#{type}_email_subject" 288 body_method = :"#{type}_email_body" 289 create_method = :"create_#{type}_email" 290 send_method = :"send_#{type}_email" 291 292 translatable_method subject_method, subject 293 auth_methods create_method, send_method 294 295 body_template = "#{type.to_s.tr('_', '-')}-email" 296 if opts[:translatable] 297 auth_value_methods body_method 298 define_method(body_method){translate(body_method, render(body_template))} 299 else 300 auth_methods body_method 301 define_method(body_method){render(body_template)} 302 end 303 304 define_method(create_method) do 305 create_email(send(subject_method), send(body_method)) 306 end 307 308 define_method(send_method) do 309 send_email(send(create_method)) 310 end 311 end
flash_key(meth, value)
[show source]
# File lib/rodauth.rb 322 def flash_key(meth, value) 323 define_method(meth){normalize_session_or_flash_key(value)} 324 auth_value_methods(meth) 325 end
internal_request_method(name=feature_name)
[show source]
# File lib/rodauth.rb 199 def internal_request_method(name=feature_name) 200 (@internal_request_methods ||= []) << name 201 end
loaded_templates(v)
[show source]
# File lib/rodauth.rb 265 def loaded_templates(v) 266 define_method(:loaded_templates) do 267 super().concat(v) 268 end 269 private :loaded_templates 270 end
redirect(name=feature_name, &block)
[show source]
# File lib/rodauth.rb 232 def redirect(name=feature_name, &block) 233 meth = :"#{name}_redirect" 234 block ||= DEFAULT_REDIRECT_BLOCK 235 define_method(meth, &block) 236 auth_value_methods meth 237 end
response(name=feature_name)
[show source]
# File lib/rodauth.rb 249 def response(name=feature_name) 250 meth = :"#{name}_response" 251 overridable_meth = :"_#{meth}" 252 notice_flash_meth = :"#{name}_notice_flash" 253 redirect_meth = :"#{name}_redirect" 254 define_method(overridable_meth) do 255 set_notice_flash send(notice_flash_meth) 256 redirect send(redirect_meth) 257 end 258 define_method(meth) do 259 require_response(overridable_meth) 260 end 261 private overridable_meth, meth 262 auth_private_methods meth 263 end
route(name=feature_name, default=name.to_s.tr('_', '-'), &block)
[show source]
# File lib/rodauth.rb 154 def route(name=feature_name, default=name.to_s.tr('_', '-'), &block) 155 route_meth = :"#{name}_route" 156 auth_value_method route_meth, default 157 158 define_method(:"#{name}_path"){|opts=OPTS| route_path(send(route_meth), opts) if send(route_meth)} 159 define_method(:"#{name}_url"){|opts=OPTS| route_url(send(route_meth), opts) if send(route_meth)} 160 161 handle_meth = :"handle_#{name}" 162 internal_handle_meth = :"_#{handle_meth}" 163 before route_meth 164 define_method(internal_handle_meth, &block) 165 166 define_method(handle_meth) do 167 request.is send(route_meth) do 168 @current_route = name 169 check_csrf if check_csrf? 170 _around_rodauth do 171 before_rodauth 172 send(internal_handle_meth, request) 173 end 174 end 175 end 176 177 routes << handle_meth 178 end
session_key(meth, value)
[show source]
# File lib/rodauth.rb 317 def session_key(meth, value) 318 define_method(meth){convert_session_key(value)} 319 auth_value_methods(meth) 320 end
translatable_method(meth, value)
[show source]
# File lib/rodauth.rb 332 def translatable_method(meth, value) 333 define_method(meth){translate(meth, value)} 334 auth_value_methods(meth) 335 end
uses_instance_variables(*ivs)
[show source]
# File lib/rodauth.rb 203 def uses_instance_variables(*ivs) 204 @instance_variables_used = ivs.freeze 205 end
view(page, title, name=feature_name)
[show source]
# File lib/rodauth.rb 239 def view(page, title, name=feature_name) 240 meth = :"#{name}_view" 241 title_meth = :"#{name}_page_title" 242 translatable_method(title_meth, title) 243 define_method(meth) do 244 view(page, send(title_meth)) 245 end 246 auth_methods meth 247 end