1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00
heartcombo--devise/lib/devise/active_record.rb

87 lines
2.6 KiB
Ruby
Raw Normal View History

module Devise
module ActiveRecord
# Shortcut method for including all devise modules inside your model.
# You can give some extra options while declaring devise in your model:
#
2009-10-20 13:31:34 -02:00
# * except: convenient option that allows you to add all devise modules,
# removing only the modules 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
2009-10-20 13:31:34 -02:00
# method to setup pepper and stretches.
2009-10-12 08:37:28 -03:00
#
# Examples:
2009-10-12 08:37:28 -03:00
#
# # include only authenticable module (default)
# devise
2009-10-12 08:37:28 -03:00
#
# # include authenticable + confirmable modules
# devise :confirmable
2009-10-12 08:37:28 -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
#
# # 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
#
# # shortcut to include all modules (same as above)
# devise :all
#
# # include all except recoverable
# devise :all, :except => :recoverable
#
def devise(*modules)
options = modules.extract_options!
options.assert_valid_keys(:except, *Devise::MODEL_CONFIG)
2009-10-20 11:55:57 -02:00
modules = Devise::ALL if modules.include?(:all)
modules -= Array(options.delete(:except)) if options.key?(:except)
modules |= [:authenticable]
2009-10-12 21:06:39 -03: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
# Convert new keys to methods which overwrites Devise defaults
2009-10-20 11:55:57 -02:00
options.each do |key, value|
case value
when Proc
define_method key, &value
next
when ActiveSupport::Duration
value = value.to_i
end
class_eval <<-END_EVAL, __FILE__, __LINE__
def #{key}
#{value.inspect}
end
END_EVAL
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 ||= []
end
end
end