Skip to content

Commit

Permalink
Kill AMo observing wrap_with_notifications since ARes was only using it
Browse files Browse the repository at this point in the history
  • Loading branch information
josh committed Sep 2, 2009
1 parent e870e24 commit 723a47b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
17 changes: 0 additions & 17 deletions activemodel/lib/active_model/observing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,6 @@ def instantiate_observers
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
Expand Down
13 changes: 12 additions & 1 deletion activeresource/lib/active_resource/observing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,18 @@ module Observing
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

0 comments on commit 723a47b

Please sign in to comment.