class Bogus::OverwritesMethods
Public Instance Methods
overwrite(object, name)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 7 def overwrite(object, name) raise "wut?" if name == :__shadow__ return if already_delegates_to_shadow?(object, name) object.extend RecordInteractions object.extend HasOverwritenMethods method = method_by_name(object, name) copy = copy(object, name) object.__overwrite__(name, method, copy) end
reset(object)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 20 def reset(object) return if object.is_a?(FakeObject) object.__reset__ end
Private Instance Methods
already_delegates_to_shadow?(object, name)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 28 def already_delegates_to_shadow?(object, name) return false unless object.is_a?(FakeObject) !Fake.instance_methods.include?(name) end
copy(object, name)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 37 def copy(object, name) method = method_by_name(object, name) return default_method(name) unless method makes_substitute_methods.stringify(method) end
default_method(name)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 43 def default_method(name) "def #{name}(*args, &block); __record__(:#{name}, *args, &block); end" end
method_by_name(object, name)
click to toggle source
# File lib/bogus/stubbing/overwrites_methods.rb, line 33 def method_by_name(object, name) object.method(name) if object.methods.include?(name) end