Module: Devise::Models
- Defined in:
- lib/devise/models.rb,
lib/devise/models/lockable.rb,
lib/devise/models/trackable.rb,
lib/devise/models/confirmable.rb,
lib/devise/models/encryptable.rb,
lib/devise/models/recoverable.rb,
lib/devise/models/timeoutable.rb,
lib/devise/models/validatable.rb,
lib/devise/models/omniauthable.rb,
lib/devise/models/registerable.rb,
lib/devise/models/rememberable.rb,
lib/devise/models/serializable.rb,
lib/devise/models/authenticatable.rb,
lib/devise/models/token_authenticatable.rb,
lib/devise/models/database_authenticatable.rb
Defined Under Namespace
Modules: Authenticatable, Confirmable, DatabaseAuthenticatable, Encryptable, Lockable, Omniauthable, Recoverable, Registerable, Rememberable, Serializable, Timeoutable, TokenAuthenticatable, Trackable, Validatable
Class Method Summary collapse
-
.config(mod, *accessors) ⇒ Object
Creates configuration values for Devise and for the given module.
Instance Method Summary collapse
-
#devise(*modules) ⇒ Object
Include the chosen devise modules in your model:.
-
#devise_modules_hook! ⇒ Object
The hook which is called inside devise.
Class Method Details
.config(mod, *accessors) ⇒ Object
Creates configuration values for Devise and for the given module.
Devise::Models.config(Devise::Authenticatable, :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.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/devise/models.rb', line 19 def self.config(mod, *accessors) #:nodoc: (class << mod; self; end).send :attr_accessor, :available_configs mod.available_configs = accessors accessors.each do |accessor| mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1 def #{accessor} if defined?(@#{accessor}) @#{accessor} elsif superclass.respond_to?(:#{accessor}) superclass.#{accessor} else Devise.#{accessor} end end def #{accessor}=(value) @#{accessor} = value end METHOD end end |
Instance Method Details
#devise(*modules) ⇒ Object
Include the chosen devise modules in your model:
devise :database_authenticatable, :confirmable, :recoverable
You can also give any of the devise configuration values in form of a hash, with specific values for this model. Please check your Devise initializer for a complete description on those values.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/devise/models.rb', line 50 def devise(*modules) include Devise::Models::Authenticatable = modules..dup selected_modules = modules.map(&:to_sym).uniq.sort_by do |s| Devise::ALL.index(s) || -1 # follow Devise::ALL order end devise_modules_hook! do selected_modules.each do |m| mod = Devise::Models.const_get(m.to_s.classify) if mod.const_defined?("ClassMethods") class_mod = mod.const_get("ClassMethods") extend class_mod if class_mod.respond_to?(:available_configs) available_configs = class_mod.available_configs available_configs.each do |config| next unless .key?(config) send(:"#{config}=", .delete(config)) end end end include mod end self.devise_modules |= selected_modules .each { |key, value| send(:"#{key}=", value) } end end |
#devise_modules_hook! ⇒ Object
The hook which is called inside devise. So your ORM can include devise compatibility stuff.
85 86 87 |
# File 'lib/devise/models.rb', line 85 def devise_modules_hook! yield end |