diff --git a/lib/devise/orm/data_mapper.rb b/lib/devise/orm/data_mapper.rb index 19a8404c..f460cb1c 100644 --- a/lib/devise/orm/data_mapper.rb +++ b/lib/devise/orm/data_mapper.rb @@ -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) \ No newline at end of file