2009-10-09 10:46:24 -03:00
|
|
|
module Devise
|
|
|
|
module ActiveRecord
|
2009-10-20 11:08:40 -02:00
|
|
|
# Shortcut method for including all devise modules inside your model.
|
|
|
|
# You can give some extra options while declaring devise in your model:
|
|
|
|
#
|
|
|
|
# * except: let's you add all devise modules, except the ones you setup here:
|
|
|
|
#
|
|
|
|
# devise :all, :except => :rememberable
|
|
|
|
#
|
|
|
|
# * pepper: setup a pepper to generate de encrypted password. By default no
|
|
|
|
# pepper is used:
|
|
|
|
#
|
|
|
|
# devise :all, :pepper => 'my_pepper'
|
|
|
|
#
|
|
|
|
# * stretches: configure how many times you want the password is reencrypted.
|
|
|
|
#
|
|
|
|
# devise :all, :stretches => 20
|
|
|
|
#
|
|
|
|
# You can refer to Authenticable for more information about writing your own
|
|
|
|
# method to setup pepper and stretches
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# Examples:
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# # include only authenticable module (default)
|
|
|
|
# devise
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# # include authenticable + confirmable modules
|
|
|
|
# devise :confirmable
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# # include authenticable + recoverable modules
|
|
|
|
# devise :recoverable
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-20 00:52:31 -02:00
|
|
|
# # include authenticable + rememberable modules
|
|
|
|
# devise :rememberable
|
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# # include authenticable + validatable modules
|
|
|
|
# devise :validatable
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-20 00:52:31 -02:00
|
|
|
# # include authenticable + confirmable + recoverable + rememberable + validatable
|
|
|
|
# devise :confirmable, :recoverable, :rememberable, :validatable
|
2009-10-12 08:37:28 -03:00
|
|
|
#
|
2009-10-09 10:46:24 -03:00
|
|
|
# # shortcut to include all modules (same as above)
|
|
|
|
# devise :all
|
2009-10-18 13:30:32 -02:00
|
|
|
#
|
2009-10-18 15:25:16 -02:00
|
|
|
# # include all except recoverable
|
2009-10-18 13:30:32 -02:00
|
|
|
# devise :all, :except => :recoverable
|
|
|
|
#
|
|
|
|
def devise(*modules)
|
|
|
|
options = modules.extract_options!
|
2009-10-20 12:49:49 -02:00
|
|
|
options.assert_valid_keys(:except, *Devise::MODEL_CONFIG)
|
2009-10-18 13:30:32 -02:00
|
|
|
|
2009-10-20 11:55:57 -02:00
|
|
|
modules = Devise::ALL if modules.include?(:all)
|
|
|
|
modules -= Array(options.delete(:except)) if options.key?(:except)
|
2009-10-18 13:30:32 -02:00
|
|
|
modules |= [:authenticable]
|
2009-10-12 21:06:39 -03:00
|
|
|
|
2009-10-18 13:30:32 -02:00
|
|
|
modules.each do |m|
|
2009-10-12 21:06:39 -03:00
|
|
|
devise_modules << m.to_sym
|
|
|
|
include Devise::Models.const_get(m.to_s.classify)
|
|
|
|
end
|
2009-10-20 11:08:40 -02:00
|
|
|
|
2009-10-20 12:49:49 -02:00
|
|
|
# Convert new keys to methods which overwrites Devise defaults
|
2009-10-20 11:55:57 -02:00
|
|
|
options.each do |key, value|
|
2009-10-20 12:49:49 -02:00
|
|
|
if value.is_a?(Proc)
|
|
|
|
define_method key, &value
|
|
|
|
else
|
|
|
|
class_eval <<-END_EVAL, __FILE__, __LINE__
|
|
|
|
def #{key}
|
|
|
|
#{value.inspect}
|
|
|
|
end
|
|
|
|
END_EVAL
|
|
|
|
end
|
2009-10-20 11:08:40 -02:00
|
|
|
end
|
2009-10-12 21:06:39 -03:00
|
|
|
end
|
|
|
|
|
2009-10-17 12:10:15 -03:00
|
|
|
# Stores all modules included inside the model, so we are able to verify
|
|
|
|
# which routes are needed.
|
2009-10-12 21:06:39 -03:00
|
|
|
def devise_modules
|
|
|
|
@devise_modules ||= []
|
2009-10-09 10:46:24 -03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|