Ensure configuration options are allowed exactly after each module is included.
This commit is contained in:
parent
d3a374777b
commit
e4902143f8
|
@ -1,6 +1,12 @@
|
||||||
* enhancements
|
* enhancements
|
||||||
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
|
* All controllers can now handle different mime types than html using Responders (by github.com/sikachu)
|
||||||
|
|
||||||
|
* bug fix
|
||||||
|
* Fix a bug where configuration options were being included too late
|
||||||
|
|
||||||
|
* backward incompatible changes
|
||||||
|
* authentication_keys are no longer considered when creating the e-mail validations, the previous behavior was buggy. You must double check if you were relying on such behavior.
|
||||||
|
|
||||||
== 1.2.1
|
== 1.2.1
|
||||||
|
|
||||||
* enhancements
|
* enhancements
|
||||||
|
|
|
@ -17,6 +17,9 @@ module Devise
|
||||||
# inside the given class.
|
# inside the given class.
|
||||||
#
|
#
|
||||||
def self.config(mod, *accessors) #:nodoc:
|
def self.config(mod, *accessors) #:nodoc:
|
||||||
|
(class << mod; self; end).send :attr_accessor, :available_configs
|
||||||
|
mod.available_configs = accessors
|
||||||
|
|
||||||
accessors.each do |accessor|
|
accessors.each do |accessor|
|
||||||
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1
|
||||||
def #{accessor}
|
def #{accessor}
|
||||||
|
@ -46,13 +49,29 @@ module Devise
|
||||||
#
|
#
|
||||||
def devise(*modules)
|
def devise(*modules)
|
||||||
include Devise::Models::Authenticatable
|
include Devise::Models::Authenticatable
|
||||||
options = modules.extract_options!
|
options = modules.extract_options!.dup
|
||||||
|
|
||||||
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
|
self.devise_modules += modules.map(&:to_sym).uniq.sort_by { |s|
|
||||||
Devise::ALL.index(s) || -1 # follow Devise::ALL order
|
Devise::ALL.index(s) || -1 # follow Devise::ALL order
|
||||||
}
|
}
|
||||||
|
|
||||||
devise_modules_hook! do
|
devise_modules_hook! do
|
||||||
devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
|
devise_modules.each do |m|
|
||||||
|
mod = Devise::Models.const_get(m.to_s.classify)
|
||||||
|
include mod
|
||||||
|
|
||||||
|
if mod.const_defined?("ClassMethods")
|
||||||
|
class_mod = mod.const_get("ClassMethods")
|
||||||
|
if class_mod.respond_to?(:available_configs)
|
||||||
|
available_configs = class_mod.available_configs
|
||||||
|
available_configs.each do |config|
|
||||||
|
next unless options.key?(config)
|
||||||
|
send(:"#{config}=", options.delete(config))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
options.each { |key, value| send(:"#{key}=", value) }
|
options.each { |key, value| send(:"#{key}=", value) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,8 +23,7 @@ module Devise
|
||||||
|
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
validates_presence_of :email, :if => :email_required?
|
validates_presence_of :email, :if => :email_required?
|
||||||
validates_uniqueness_of :email, :scope => authentication_keys[1..-1],
|
validates_uniqueness_of :email, :case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
||||||
:case_sensitive => (case_insensitive_keys != false), :allow_blank => true
|
|
||||||
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
validates_format_of :email, :with => email_regexp, :allow_blank => true
|
||||||
|
|
||||||
with_options :if => :password_required? do |v|
|
with_options :if => :password_required? do |v|
|
||||||
|
|
Loading…
Reference in New Issue