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

89 lines
2.9 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 11:31:34 -04: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
#
2009-10-30 05:23:47 -04:00
# * confirm_within: the time you want your user to confirm it's account. During
# this time he will be able to access your application without confirming.
#
2009-10-30 05:23:47 -04:00
# devise :all, :confirm_within => 7.days
#
# * remember_for: the time the user will be remembered without asking for
# credentials again.
#
# devise :all, :remember_for => 2.weeks
#
# You can refer to Authenticable, Confirmable and Rememberable for more
# information about writing your own method to setup each model apart.
2009-10-12 07:37:28 -04:00
#
# Examples:
2009-10-12 07:37:28 -04:00
#
# # include only authenticatable module (default)
# devise
2009-10-12 07:37:28 -04:00
#
# # include authenticatable + confirmable modules
# devise :confirmable
2009-10-12 07:37:28 -04:00
#
# # include authenticatable + recoverable modules
# devise :recoverable
2009-10-12 07:37:28 -04:00
#
# # include authenticatable + rememberable modules
2009-10-19 22:52:31 -04:00
# devise :rememberable
#
# # include authenticatable + validatable modules
# devise :validatable
2009-10-12 07:37:28 -04:00
#
# # include authenticatable + confirmable + recoverable + rememberable + validatable
2009-10-19 22:52:31 -04:00
# devise :confirmable, :recoverable, :rememberable, :validatable
2009-10-12 07:37:28 -04: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!
# TODO Remove me in a next release
if modules.include?(:authenticable)
modules.delete(:authenticable)
modules.unshift(:authenticatable)
ActiveSupport::Deprecation.warn "devise :authenticate is deprecated, use authenticatable instead"
end
2009-10-22 12:19:01 -04:00
modules = Devise::ALL if modules.include?(:all)
modules -= Array(options.delete(:except))
modules = [:authenticatable] | modules
2009-10-12 20:06:39 -04:00
modules.each do |m|
2009-10-12 20:06:39 -04: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-22 12:19:01 -04:00
options.each { |key, value| send(:"#{key}=", value) }
2009-10-12 20:06:39 -04:00
end
2009-10-17 11:10:15 -04:00
# Stores all modules included inside the model, so we are able to verify
# which routes are needed.
2009-10-12 20:06:39 -04:00
def devise_modules
@devise_modules ||= []
end
end
end