2010-03-18 13:53:42 -04:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
2007-12-28 12:02:01 -05:00
|
|
|
class SetterTrap < ActiveSupport::BasicObject
|
2007-01-24 13:29:07 -05:00
|
|
|
class << self
|
|
|
|
def rollback_sets(obj)
|
2009-02-06 15:18:24 -05:00
|
|
|
trapped = new(obj)
|
|
|
|
yield(trapped).tap { trapped.rollback_sets }
|
2007-01-24 13:29:07 -05:00
|
|
|
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
|