aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activemodel/lib/active_model/observing.rb17
-rw-r--r--activeresource/lib/active_resource/observing.rb13
2 files changed, 12 insertions, 18 deletions
diff --git a/activemodel/lib/active_model/observing.rb b/activemodel/lib/active_model/observing.rb
index 3b230c43b9..d9d1ab8967 100644
--- a/activemodel/lib/active_model/observing.rb
+++ b/activemodel/lib/active_model/observing.rb
@@ -40,23 +40,6 @@ module ActiveModel
observers.each { |o| instantiate_observer(o) }
end
- # Wraps methods with before and after notifications.
- #
- # wrap_with_notifications :create, :save, :update, :destroy
- def wrap_with_notifications(*methods)
- methods.each do |method|
- class_eval(<<-EOS, __FILE__, __LINE__ + 1)
- def #{method}_with_notifications(*args, &block)
- notify_observers(:before_#{method})
- result = #{method}_without_notifications(*args, &block)
- notify_observers(:after_#{method})
- result
- end
- EOS
- alias_method_chain(method, :notifications)
- end
- end
-
protected
def instantiate_observer(observer) #:nodoc:
# string/symbol
diff --git a/activeresource/lib/active_resource/observing.rb b/activeresource/lib/active_resource/observing.rb
index 94836f4bb1..3c74d49c80 100644
--- a/activeresource/lib/active_resource/observing.rb
+++ b/activeresource/lib/active_resource/observing.rb
@@ -4,7 +4,18 @@ module ActiveResource
include ActiveModel::Observing
included do
- wrap_with_notifications :create, :save, :update, :destroy
+ %w( create save update destroy ).each do |method|
+ class_eval(<<-EOS, __FILE__, __LINE__ + 1)
+ def #{method}_with_notifications(*args, &block)
+ notify_observers(:before_#{method})
+ if result = #{method}_without_notifications(*args, &block)
+ notify_observers(:after_#{method})
+ end
+ result
+ end
+ EOS
+ alias_method_chain(method, :notifications)
+ end
end
end
end