Class: ResourceMapper::ResponseCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/resource_mapper/response_collector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResponseCollector

Returns a new instance of ResponseCollector.



8
9
10
# File 'lib/resource_mapper/response_collector.rb', line 8

def initialize
  @responses = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, &block) ⇒ Object



12
13
14
15
# File 'lib/resource_mapper/response_collector.rb', line 12

def method_missing(method_name, &block)
  @responses.delete self[method_name]
  @responses << [method_name, block || nil]
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



4
5
6
# File 'lib/resource_mapper/response_collector.rb', line 4

def responses
  @responses
end

Instance Method Details

#[](symbol) ⇒ Object



17
18
19
# File 'lib/resource_mapper/response_collector.rb', line 17

def [](symbol)
  @responses.find { |method, block| method == symbol }
end

#dupObject



21
22
23
24
25
# File 'lib/resource_mapper/response_collector.rb', line 21

def dup
  returning ResponseCollector.new do |duplicate|
    duplicate.instance_variable_set(:@responses, responses.dup)
  end
end