2009-07-21 00:57:01 -04:00
|
|
|
module ActiveResource
|
|
|
|
module Observing
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
include ActiveModel::Observing
|
|
|
|
|
|
|
|
included do
|
2009-09-02 12:44:36 -04:00
|
|
|
%w( create save update destroy ).each do |method|
|
2011-05-01 14:50:53 -04:00
|
|
|
# def create_with_notifications(*args, &block)
|
|
|
|
# notify_observers(:before_create)
|
|
|
|
# if result = create_without_notifications(*args, &block)
|
|
|
|
# notify_observers(:after_create)
|
|
|
|
# end
|
|
|
|
# result
|
|
|
|
# end
|
|
|
|
# alias_method_chain(create, :notifications)
|
2009-09-02 12:44:36 -04:00
|
|
|
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
|
2009-07-21 00:57:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|