Skip to content

Commit

Permalink
Fix compatibility with Mongoid and Datamapper, closes heartcombo#206.
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Apr 15, 2010
1 parent 1db86a0 commit 9291ab5
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions lib/devise/models.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
module Devise
module Models
class << self
def hook(base)
base.class_eval do
class_attribute :devise_modules, :instance_writer => false
self.devise_modules ||= []
end
end

alias :included :hook
alias :extended :hook
end

# Creates configuration values for Devise and for the given module.
#
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
Expand Down Expand Up @@ -57,6 +45,7 @@ def #{accessor}=(value)
# for a complete description on those values.
#
def devise(*modules)
define_devise_class_attributes!
include Devise::Models::Authenticatable
options = modules.extract_options!

Expand Down Expand Up @@ -88,26 +77,30 @@ def devise_modules_hook!
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)
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

Expand Down

0 comments on commit 9291ab5

Please sign in to comment.