Class: AndSon::StoredResponses

Inherits:
Object
  • Object
show all
Defined in:
lib/and-son/stored_responses.rb

Defined Under Namespace

Classes: Stub

Instance Method Summary collapse

Constructor Details

#initializeStoredResponses

Returns a new instance of StoredResponses.



8
9
10
# File 'lib/and-son/stored_responses.rb', line 8

def initialize
  @hash = Hash.new{ |h, k| h[k] = Stub.new }
end

Instance Method Details

#add(name, &block) ⇒ Object



12
13
14
# File 'lib/and-son/stored_responses.rb', line 12

def add(name, &block)
  @hash[name].tap{ |s| s.set_default_proc(&block) }
end

#get(name, params) ⇒ Object



16
17
18
19
# File 'lib/and-son/stored_responses.rb', line 16

def get(name, params)
  response = @hash[name].call(params)
  AndSon::Response.new(response)
end

#remove(name) ⇒ Object



21
22
23
# File 'lib/and-son/stored_responses.rb', line 21

def remove(name)
  @hash.delete(name)
end

#remove_allObject



25
26
27
# File 'lib/and-son/stored_responses.rb', line 25

def remove_all
  @hash.clear
end