Class: Spy::Agency
Overview
Manages all the spies
Instance Method Summary collapse
-
#active?(spy) ⇒ Boolean
checks to see if a spy is hooked.
-
#clear! ⇒ self
clears records.
-
#dissolve! ⇒ self
unhooks all spies and clears records.
-
#find(id) ⇒ Nil, ...
given a spy ID it will return the associated spy.
-
#initialize ⇒ Agency
constructor
A new instance of Agency.
-
#recruit(spy) ⇒ spy
Record that a spy was initialized and hooked.
-
#retire(spy) ⇒ spy
remove spy from the records.
-
#spies ⇒ Array<Subroutine, Constant, Double>
returns all the spies that have been initialized since the creation of this agency.
Constructor Details
#initialize ⇒ Agency
Returns a new instance of Agency.
9 10 11 |
# File 'lib/spy/agency.rb', line 9 def initialize clear! end |
Instance Method Details
#active?(spy) ⇒ Boolean
checks to see if a spy is hooked
40 41 42 43 |
# File 'lib/spy/agency.rb', line 40 def active?(spy) check_spy!(spy) @spies.has_key?(spy.object_id) end |
#clear! ⇒ self
clears records
56 57 58 59 |
# File 'lib/spy/agency.rb', line 56 def clear! @spies = {} self end |
#dissolve! ⇒ self
unhooks all spies and clears records
47 48 49 50 51 52 |
# File 'lib/spy/agency.rb', line 47 def dissolve! @spies.values.each do |spy| spy.unhook if spy.respond_to?(:unhook) end clear! end |
#find(id) ⇒ Nil, ...
given a spy ID it will return the associated spy
16 17 18 |
# File 'lib/spy/agency.rb', line 16 def find(id) @spies[id] end |
#recruit(spy) ⇒ spy
Record that a spy was initialized and hooked
23 24 25 26 27 |
# File 'lib/spy/agency.rb', line 23 def recruit(spy) raise AlreadyStubbedError if @spies[spy.object_id] check_spy!(spy) @spies[spy.object_id] = spy end |
#retire(spy) ⇒ spy
remove spy from the records
32 33 34 35 |
# File 'lib/spy/agency.rb', line 32 def retire(spy) raise NoSpyError unless @spies[spy.object_id] @spies.delete(spy.object_id) end |
#spies ⇒ Array<Subroutine, Constant, Double>
returns all the spies that have been initialized since the creation of this agency
64 65 66 |
# File 'lib/spy/agency.rb', line 64 def spies @spies.values end |