Class: Devise::Mapping
- Inherits:
-
Object
- Object
- Devise::Mapping
- Defined in:
- lib/devise/mapping.rb
Overview
Responsible for handling devise mappings and routes configuration. Each resource configured by devise_for in routes is actually creating a mapping object. You can refer to devise_for in routes for usage options.
The required value in devise_for is actually not used internally, but it’s inflected to find all other values.
map.devise_for :users
mapping = Devise.mappings[:user]
mapping.name #=> :user
# is the scope used in controllers and warden, given in the route as :singular.
mapping.as #=> "users"
# how the mapping should be search in the path, given in the route as :as.
mapping.to #=> User
# is the class to be loaded from routes, given in the route as :class_name.
mapping.for #=> [:authenticable]
# is the modules included in the class
Instance Attribute Summary collapse
-
#as ⇒ Object
readonly
:nodoc:.
-
#name ⇒ Object
readonly
:nodoc:.
-
#path_names ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#allows?(controller) ⇒ Boolean
Check if the respective controller has a module in the mapping class.
-
#for ⇒ Object
Return modules for the mapping.
-
#initialize(name, options) ⇒ Mapping
constructor
A new instance of Mapping.
-
#to ⇒ Object
Reload mapped class each time when cache_classes is false.
Constructor Details
#initialize(name, options) ⇒ Mapping
Returns a new instance of Mapping.
27 28 29 30 31 32 33 |
# File 'lib/devise/mapping.rb', line 27 def initialize(name, ) @as = ([:as] || name).to_sym @klass = ([:class_name] || name.to_s.classify).to_s @name = ([:singular] || name.to_s.singularize).to_sym @path_names = [:path_names] || {} setup_path_names end |
Instance Attribute Details
#as ⇒ Object (readonly)
:nodoc:
25 26 27 |
# File 'lib/devise/mapping.rb', line 25 def as @as end |
#name ⇒ Object (readonly)
:nodoc:
25 26 27 |
# File 'lib/devise/mapping.rb', line 25 def name @name end |
#path_names ⇒ Object (readonly)
:nodoc:
25 26 27 |
# File 'lib/devise/mapping.rb', line 25 def path_names @path_names end |
Instance Method Details
#allows?(controller) ⇒ Boolean
Check if the respective controller has a module in the mapping class.
49 50 51 |
# File 'lib/devise/mapping.rb', line 49 def allows?(controller) self.for.include?(CONTROLLERS[controller.to_sym]) end |
#for ⇒ Object
Return modules for the mapping.
36 37 38 |
# File 'lib/devise/mapping.rb', line 36 def for @for ||= to.devise_modules end |
#to ⇒ Object
Reload mapped class each time when cache_classes is false.
41 42 43 44 45 46 |
# File 'lib/devise/mapping.rb', line 41 def to return @to if @to klass = @klass.constantize @to = klass if Rails.configuration.cache_classes klass end |