lib/devise/orm/data_mapper/compatibility.rb in dm-devise-1.5.0 vs lib/devise/orm/data_mapper/compatibility.rb in dm-devise-2.0.0
- old
+ new
@@ -4,31 +4,27 @@
module Compatibility
extend ActiveSupport::Concern
module ClassMethods
# Hooks for confirmable
- def before_create(*args)
- wrap_hook(:before, :create, *args)
+ [:before, :after].each do |action|
+ [:create, :update, :save].each do |method|
+ define_method(:"#{action}_#{method}") do |*args|
+ wrap_hook(action, method, *args)
+ end
+ end
end
- def after_create(*args)
- wrap_hook(:after, :create, *args)
- end
-
- def before_save(*args)
- wrap_hook(:before, :save, *args)
- end
-
def before_validation(*args)
wrap_hook(:before, :valid?, *args)
end
def wrap_hook(action, method, *args)
options = args.extract_options!
args.each do |callback|
- callback_method = :"#{callback}_callback_wrap"
+ callback_method = "#{action}_#{method}_#{callback}_callback_wrap".gsub('?', '').to_sym
send action, method, callback_method
class_eval <<-METHOD, __FILE__, __LINE__ + 1
def #{callback_method}
#{callback} if #{options[:if] || true}
end
@@ -41,11 +37,11 @@
dirty?
end
def save(options=nil)
if options.is_a?(Hash) && options[:validate] == false
- save!
+ _persist
else
super()
end
end
@@ -61,9 +57,13 @@
!valid?
end
def email_changed?
attribute_dirty?(:email)
+ end
+
+ def email_was
+ original_attributes[:email]
end
end
end
end
end