Method: Devise::Models.config

Defined in:
lib/devise/models.rb

.config(mod, *accessors) ⇒ Object

Creates configuration values for Devise and for the given module.

Devise::Models.config(Devise::Models::DatabaseAuthenticatable, :stretches)

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.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/devise/models.rb', line 31

def self.config(mod, *accessors) #:nodoc:
  class << mod; attr_accessor :available_configs; end
  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