Class: AndSon::StoredResponses
- Inherits:
-
Object
- Object
- AndSon::StoredResponses
- Defined in:
- lib/and-son/stored_responses.rb
Defined Under Namespace
Classes: Stub
Instance Method Summary collapse
- #add(name, &block) ⇒ Object
- #get(name, params) ⇒ Object
-
#initialize ⇒ StoredResponses
constructor
A new instance of StoredResponses.
- #remove(name) ⇒ Object
- #remove_all ⇒ Object
Constructor Details
#initialize ⇒ StoredResponses
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_all ⇒ Object
25 26 27 |
# File 'lib/and-son/stored_responses.rb', line 25 def remove_all @hash.clear end |