class Spy::Registry

Responsible for managing the top-level state of which spies exist.

Public Class Methods

new() click to toggle source
# File lib/spy/registry.rb, line 6
def initialize
  @store = {}
end

Public Instance Methods

get(blueprint) click to toggle source
# File lib/spy/registry.rb, line 39
def get(blueprint)
  key = blueprint.to_s
  @store[key]
end
insert(blueprint, spy) click to toggle source

Keeps track of the spy for later management. Ensures spy uniqueness

@param [Spy::Blueprint] @param [Spy::Instance] spy - the instantiated spy @raises [Spy::Errors::AlreadySpiedError] if the spy is already being

tracked
# File lib/spy/registry.rb, line 16
def insert(blueprint, spy)
  key = blueprint.to_s
  raise Errors::AlreadySpiedError if @store[key]
  @store[key] = [blueprint, spy]
end
remove(blueprint) click to toggle source

Stops tracking the spy

@param [Spy::Blueprint] @raises [Spy::Errors::MethodNotSpiedError] if the spy isn't being tracked

# File lib/spy/registry.rb, line 26
def remove(blueprint)
  key = blueprint.to_s
  raise Errors::MethodNotSpiedError unless @store[key]
  @store.delete(key)[1]
end
remove_all() click to toggle source

Stops tracking all spies

# File lib/spy/registry.rb, line 33
def remove_all
  store = @store
  @store = {}
  store.values.map(&:last)
end