Class: Spy::Collection::Store

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

Overview

Works with Entry abstractions to allow the store data structure to be easily swapped

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



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

def initialize
  @internal = {}
end

Instance Method Details

#eachObject



20
21
22
23
24
25
# File 'lib/spy/collection/store.rb', line 20

def each
  e = Enumerator.new do |y|
    @internal.values.each {|v| y << v}
  end
  block_given? ? e.each(&Proc.new) : e
end

#empty?Boolean

Returns:

  • (Boolean)


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

def empty?
  none?
end

#insert(entry) ⇒ Object



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

def insert(entry)
  @internal[entry.key] = entry
end

#remove(entry) ⇒ Object



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

def remove(entry)
  @internal.delete(entry.key)
end