Class: Spy::Collection

Inherits:
Object
  • Object
show all
Includes:
Enumerable, SpyHelper
Defined in:
lib/spy/collection.rb,
lib/spy/collection/entry.rb

Defined Under Namespace

Modules: SpyHelper Classes: Entry

Instance Method Summary collapse

Methods included from SpyHelper

#<<, #pop

Constructor Details

#initializeCollection

Returns a new instance of Collection.



7
8
9
# File 'lib/spy/collection.rb', line 7

def initialize
  @store = {}
end

Instance Method Details

#eachObject



27
28
29
# File 'lib/spy/collection.rb', line 27

def each
  @store.keys.each {|k| yield Entry.parse(k)}
end

#insert(entry) ⇒ Object



11
12
13
14
# File 'lib/spy/collection.rb', line 11

def insert(entry)
  raise Errors::AlreadySpiedError if include?(entry)
  @store[entry.key] = entry
end

#remove(entry) ⇒ Object



16
17
18
19
# File 'lib/spy/collection.rb', line 16

def remove(entry)
  raise Errors::MethodNotSpiedError unless include?(entry)
  @store.delete(entry.key).value
end

#remove_allObject

Removes each element from the collection and calls the block with each deleted element



23
24
25
# File 'lib/spy/collection.rb', line 23

def remove_all
  map {|e| yield remove(e)}
end