mirror of
https://github.com/heartcombo/devise.git
synced 2026-04-28 03:00:29 -04:00
Do not require ActiveRecord to be loaded to use Devise.
This commit is contained in:
@@ -9,54 +9,11 @@ module Devise
|
||||
}.freeze
|
||||
|
||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
|
||||
|
||||
# Creates configuration values for Devise and for the given module.
|
||||
#
|
||||
# Devise.model_config(Devise::Authenticable, :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.
|
||||
#
|
||||
def self.model_config(mod, accessor, default=nil) #:nodoc:
|
||||
mattr_accessor accessor
|
||||
send(:"#{accessor}=", default)
|
||||
|
||||
mod.class_eval <<-METHOD, __FILE__, __LINE__
|
||||
def #{accessor}
|
||||
self.class.#{accessor}
|
||||
end
|
||||
METHOD
|
||||
|
||||
mod.const_get(:ClassMethods).class_eval <<-METHOD, __FILE__, __LINE__
|
||||
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
|
||||
|
||||
# Devise initialization process goes like this:
|
||||
#
|
||||
# 1) Include Devise::ActiveRecord and Devise::Migrations
|
||||
# 1) Includes in Devise::ActiveRecord and Devise::Migrations
|
||||
# 2) Load and config warden
|
||||
# 3) Load devise mapping structure
|
||||
# 4) Add routes extensions
|
||||
@@ -64,8 +21,11 @@ end
|
||||
# 6) Include filters and helpers in controllers and views
|
||||
#
|
||||
Rails.configuration.after_initialize do
|
||||
ActiveRecord::Base.extend Devise::ActiveRecord
|
||||
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Migrations
|
||||
if defined?(ActiveRecord)
|
||||
ActiveRecord::Base.extend Devise::Models
|
||||
ActiveRecord::ConnectionAdapters::TableDefinition.send :include, Devise::Migrations
|
||||
end
|
||||
|
||||
I18n.load_path.unshift File.expand_path(File.join(File.dirname(__FILE__), 'devise', 'locales', 'en.yml'))
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,57 @@
|
||||
module Devise
|
||||
module ActiveRecord
|
||||
module Models
|
||||
# Creates configuration values for Devise and for the given module.
|
||||
#
|
||||
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
|
||||
#
|
||||
# The line above creates:
|
||||
#
|
||||
# 1) An accessor called Devise::Models.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.
|
||||
#
|
||||
def self.config(mod, accessor, default=nil) #:nodoc:
|
||||
mattr_accessor accessor
|
||||
send(:"#{accessor}=", default)
|
||||
|
||||
# TODO Remove me in a next release
|
||||
Devise.class_eval <<-METHOD, __FILE__, __LINE__
|
||||
def self.#{accessor}=(value)
|
||||
ActiveSupport::Deprecation.warn "Devise.#{accessor}= is deprecated, " <<
|
||||
"use Devise::Models.#{accessor}= instead."
|
||||
Devise::Models.#{accessor} = value
|
||||
end
|
||||
METHOD
|
||||
|
||||
mod.class_eval <<-METHOD, __FILE__, __LINE__
|
||||
def #{accessor}
|
||||
self.class.#{accessor}
|
||||
end
|
||||
METHOD
|
||||
|
||||
mod.const_get(:ClassMethods).class_eval <<-METHOD, __FILE__, __LINE__
|
||||
def #{accessor}
|
||||
if defined?(@#{accessor})
|
||||
@#{accessor}
|
||||
elsif superclass.respond_to?(:#{accessor})
|
||||
superclass.#{accessor}
|
||||
else
|
||||
Devise::Models.#{accessor}
|
||||
end
|
||||
end
|
||||
|
||||
def #{accessor}=(value)
|
||||
@#{accessor} = value
|
||||
end
|
||||
METHOD
|
||||
end
|
||||
|
||||
# Shortcut method for including all devise modules inside your model.
|
||||
# You can give some extra options while declaring devise in your model:
|
||||
#
|
||||
@@ -90,8 +90,8 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
Devise.model_config(self, :pepper)
|
||||
Devise.model_config(self, :stretches, 10)
|
||||
Devise::Models.config(self, :pepper)
|
||||
Devise::Models.config(self, :stretches, 10)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,7 +150,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
Devise.model_config(self, :confirm_within, 0.days)
|
||||
Devise::Models.config(self, :confirm_within, 0.days)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -89,7 +89,7 @@ module Devise
|
||||
end
|
||||
end
|
||||
|
||||
Devise.model_config(self, :remember_for, 2.weeks)
|
||||
Devise::Models.config(self, :remember_for, 2.weeks)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user