1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activeresource/test/setter_trap.rb
Sebastian Martinez bc36618ae6 added require abstract_unit on setter_trap.rb
Signed-off-by: wycats <wycats@gmail.com>
2010-03-18 11:32:51 -07:00

28 lines
544 B
Ruby

require 'abstract_unit'
class SetterTrap < ActiveSupport::BasicObject
class << self
def rollback_sets(obj)
trapped = new(obj)
yield(trapped).tap { trapped.rollback_sets }
end
end
def initialize(obj)
@cache = {}
@obj = obj
end
def respond_to?(method)
@obj.respond_to?(method)
end
def method_missing(method, *args, &proc)
@cache[method] ||= @obj.send($`) if method.to_s =~ /=$/
@obj.send method, *args, &proc
end
def rollback_sets
@cache.each { |k, v| @obj.send k, v }
end
end