Module: Devise
- Defined in:
- lib/devise.rb,
lib/devise/failure.rb,
lib/devise/mapping.rb,
lib/devise/version.rb,
lib/devise/migrations.rb,
lib/devise/active_record.rb,
lib/devise/strategies/base.rb,
lib/devise/models/confirmable.rb,
lib/devise/models/recoverable.rb,
lib/devise/models/validatable.rb,
lib/devise/controllers/filters.rb,
lib/devise/controllers/helpers.rb,
lib/devise/models/rememberable.rb,
lib/devise/models/authenticable.rb,
lib/devise/controllers/url_helpers.rb,
lib/devise/strategies/rememberable.rb,
lib/devise/strategies/authenticable.rb
Defined Under Namespace
Modules: ActiveRecord, Controllers, Failure, Migrations, Models, Strategies Classes: Mapping
Constant Summary collapse
- ALL =
[:authenticable, :confirmable, :recoverable, :rememberable, :validatable].freeze
- CONTROLLERS =
Maps controller names to devise modules
{ :sessions => :authenticable, :passwords => :recoverable, :confirmations => :confirmable }.freeze
- TRUE_VALUES =
[true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
- VERSION =
"0.2.3".freeze
Class Method Summary collapse
-
.find_mapping_by_path(path) ⇒ Object
Loop through all mappings looking for a map that matches with the requested path (ie /users/sign_in).
-
.model_config(mod, accessor, default = nil) ⇒ Object
Creates configuration values for Devise and for the given module.
Class Method Details
.find_mapping_by_path(path) ⇒ Object
Loop through all mappings looking for a map that matches with the requested path (ie /users/sign_in). The important part here is the key :users. If no map is found just returns nil.
85 86 87 88 89 90 91 92 93 94 |
# File 'lib/devise/mapping.rb', line 85 def self.find_mapping_by_path(path) route = path.split("/")[1] return nil unless route route = route.to_sym mappings.each do |key, map| return map if map.as == route.to_sym end nil end |
.model_config(mod, accessor, default = nil) ⇒ Object
Creates configuration values for Devise and for the given module.
Devise.model_config(Devise::Authenticable, :stretches, 10)
The line above creates:
1) An accessor called Devise.stretches, which value is used by default;
2) Some class methods for your model Model.stretches and Model.stretches=
which have higher priority than Devise.stretches;
3) And an instance method stretches.
To add the class methods you need to have a module ClassMethods defined inside the given class.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/devise.rb', line 29 def self.model_config(mod, accessor, default=nil) #:nodoc: mattr_accessor accessor send(:"#{accessor}=", default) mod.class_eval " def \#{accessor}\n self.class.\#{accessor}\n end\n METHOD\n\n mod.const_get(:ClassMethods).class_eval <<-METHOD, __FILE__, __LINE__\n def \#{accessor}\n if defined?(@\#{accessor})\n @\#{accessor}\n elsif superclass.respond_to?(:\#{accessor})\n superclass.\#{accessor}\n else\n Devise.\#{accessor}\n end\n end\n\n def \#{accessor}=(value)\n @\#{accessor} = value\n end\n METHOD\nend\n", __FILE__, __LINE__ |