Class: Spy::Registry
- Inherits:
-
Object
- Object
- Spy::Registry
- Defined in:
- lib/spy/registry.rb
Overview
Responsible for managing the top-level state of which spies exist.
Instance Method Summary collapse
-
#include?(spied, method) ⇒ Boolean
Returns whether or not the object and method are already being spied on.
-
#insert(spied, method, spy) ⇒ Object
Keeps track of the spy for later management.
-
#remove(spied, method) ⇒ Object
Stops tracking the spy.
-
#remove_all ⇒ Object
Stops tracking all spies.
Instance Method Details
#include?(spied, method) ⇒ Boolean
Returns whether or not the object and method are already being spied on
45 46 47 48 |
# File 'lib/spy/registry.rb', line 45 def include?(spied, method) entry = RegistryEntry.new(spied, method) store.include? entry end |
#insert(spied, method, spy) ⇒ Object
Keeps track of the spy for later management. Ensures spy uniqueness
15 16 17 18 19 |
# File 'lib/spy/registry.rb', line 15 def insert(spied, method, spy) entry = RegistryEntry.new(spied, method, spy) raise Errors::AlreadySpiedError if store.include? entry store.insert(entry) end |
#remove(spied, method) ⇒ Object
Stops tracking the spy
26 27 28 29 30 |
# File 'lib/spy/registry.rb', line 26 def remove(spied, method) entry = RegistryEntry.new(spied, method, nil) raise Errors::MethodNotSpiedError unless store.include? entry store.remove(entry).spy end |
#remove_all ⇒ Object
Stops tracking all spies
36 37 38 39 |
# File 'lib/spy/registry.rb', line 36 def remove_all store.map { |e| yield remove(e.spied, e.method) } raise Errors::UnableToEmptySpyRegistryError unless store.empty? end |