Class: Gimme::Store

Inherits:
Object
  • Object
show all
Defined in:
lib/gimme/store.rb

Direct Known Subclasses

ClassMethodStore, InvocationStore, StubbingStore

Instance Method Summary collapse

Constructor Details

#initializeStore

Returns a new instance of Store.



5
6
7
8
9
10
# File 'lib/gimme/store.rb', line 5

def initialize
  @store = {}
  Gimme.on_reset(:each) do
    @store.clear
  end
end

Instance Method Details

#clearObject



34
35
36
# File 'lib/gimme/store.rb', line 34

def clear
  @store.clear
end

#get(double, method = nil, args = nil) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/gimme/store.rb', line 23

def get(double, method=nil, args=nil)
  id = double.__id__
  if !method
    @store[id]
  elsif @store[id] && !args
    @store[id][method]
  elsif @store[id] && @store[id][method]
    @store[id][method][args]
  end
end

#resetObject



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

def reset
  @store = {}
end

#set(double, method, args, content) ⇒ Object



16
17
18
19
20
21
# File 'lib/gimme/store.rb', line 16

def set(double, method, args, content)
  id = double.__id__
  @store[id] ||= {}
  @store[id][method] ||= {}
  @store[id][method][args] = content
end