diff --git a/lib/devise/mapping.rb b/lib/devise/mapping.rb index 58cd3903..6e654c18 100644 --- a/lib/devise/mapping.rb +++ b/lib/devise/mapping.rb @@ -77,7 +77,7 @@ module Devise # Return modules for the mapping. def modules - @modules ||= to.devise_modules + @modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : [] end # Gives the class the mapping points to. diff --git a/lib/devise/models.rb b/lib/devise/models.rb index 7d02244e..51438f64 100644 --- a/lib/devise/models.rb +++ b/lib/devise/models.rb @@ -45,7 +45,6 @@ module Devise # for a complete description on those values. # def devise(*modules) - define_devise_class_attributes! include Devise::Models::Authenticatable options = modules.extract_options! @@ -75,32 +74,6 @@ module Devise def devise_modules_hook! yield end - - # Find an initialize a record setting an error if it can't be found. - def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc: - if value.present? - conditions = { attribute => value } - record = find(:first, :conditions => conditions) - end - - unless record - record = new - if value.present? - record.send(:"#{attribute}=", value) - else - error = :blank - end - record.errors.add(attribute, error) - end - - record - end - - def define_devise_class_attributes! #:nodoc: - return if respond_to?(:devise_modules) - class_attribute :devise_modules, :instance_writer => false - self.devise_modules = [] - end end end diff --git a/lib/devise/models/authenticatable.rb b/lib/devise/models/authenticatable.rb index 3c9a18e2..15182171 100644 --- a/lib/devise/models/authenticatable.rb +++ b/lib/devise/models/authenticatable.rb @@ -39,6 +39,11 @@ module Devise module Authenticatable extend ActiveSupport::Concern + included do + class_attribute :devise_modules, :instance_writer => false + self.devise_modules ||= [] + end + # Check if the current object is valid for authentication. This method and find_for_authentication # are the methods used in a Warden::Strategy to check if a model should be signed in or not. # @@ -86,6 +91,26 @@ module Devise def find_for_authentication(conditions) find(:first, :conditions => conditions) end + + # Find an initialize a record setting an error if it can't be found. + def find_or_initialize_with_error_by(attribute, value, error=:invalid) #:nodoc: + if value.present? + conditions = { attribute => value } + record = find(:first, :conditions => conditions) + end + + unless record + record = new + if value.present? + record.send(:"#{attribute}=", value) + else + error = :blank + end + record.errors.add(attribute, error) + end + + record + end end end end