More DataMapper compatibility

This commit is contained in:
lancecarlson 2010-01-07 22:48:23 +01:00 committed by José Valim
parent 6517b358a1
commit ab57cdfb4a
1 changed files with 28 additions and 12 deletions

View File

@ -1,8 +1,20 @@
module Devise
module Orm
module DataMapper
module InstanceMethods
def save(flag=nil)
if flag == false
save!
else
super()
end
end
end
def self.included_modules_hook(klass, modules)
klass.send :extend, self
klass.send :include, InstanceMethods
yield
modules.each do |mod|
@ -19,11 +31,24 @@ module Devise
# Hooks for confirmable
def before_create(*args)
before :create, *args
wrap_hook(:before, *args)
end
def after_create(*args)
after :create, *args
wrap_hook(:after, *args)
end
def wrap_hook(action, *args)
options = args.extract_options!
args.each do |callback|
send action, :create, callback
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{callback}
super if #{options[:if] || true}
end
METHOD
end
end
# Add ActiveRecord like finder
@ -39,15 +64,6 @@ module Devise
end
end
# In Datamapper, we need to call save! if we don't want to execute callbacks.
def save(flag=nil)
if flag == false
save!
else
super()
end
end
# Tell how to apply schema methods. This automatically maps :limit to
# :length and :null to :nullable.
def apply_schema(name, type, options={})
@ -64,4 +80,4 @@ module Devise
end
end
DataMapper::Model.send(:include, Devise::Models)
DataMapper::Model.send(:include, Devise::Models)