Class: Spy::Core
- Inherits:
-
Object
- Object
- Spy::Core
- Defined in:
- lib/spy/core.rb
Overview
The main internal API. This is used directly by ‘Spy::API` and is the primary control center for creating and removing spies.
Syntactic sugar (like ‘Spy.restore(object, msg)` vs `Spy.restore(:all)`) should be handled in `Spy::API` and utilize `Spy::Core`
Instance Method Summary collapse
-
#add_spy(object, method) ⇒ Object
Start spying on the given object and method.
-
#remove_all_spies ⇒ Object
Stops spying on all objects and methods.
-
#remove_spy(object, method) ⇒ Object
Stop spying on the given object and method.
Instance Method Details
#add_spy(object, method) ⇒ Object
Start spying on the given object and method
19 20 21 22 23 24 |
# File 'lib/spy/core.rb', line 19 def add_spy(object, method) raise Errors::AlreadySpiedError if registry.include?(object, method) spy = Instance.new(object, method) registry.insert(object, method, spy) spy.start end |
#remove_all_spies ⇒ Object
Stops spying on all objects and methods
41 42 43 |
# File 'lib/spy/core.rb', line 41 def remove_all_spies registry.remove_all(&:stop) end |
#remove_spy(object, method) ⇒ Object
Stop spying on the given object and method
32 33 34 35 |
# File 'lib/spy/core.rb', line 32 def remove_spy(object, method) spy = registry.remove(object, method) spy.stop end |