Class: Resourcelogic::ResponseCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/resourcelogic/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/resourcelogic/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
16
17
18
19
20
# File 'lib/resourcelogic/response_collector.rb', line 12

def method_missing(method_name, &block)
  @responses.delete self[method_name]
  value = [method_name, block || nil]
  if method_name == :html
    @responses.unshift(value)
  else
    @responses << value
  end
end

Instance Attribute Details

#responsesObject (readonly)

Returns the value of attribute responses.



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

def responses
  @responses
end

Instance Method Details

#[](symbol) ⇒ Object



22
23
24
# File 'lib/resourcelogic/response_collector.rb', line 22

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

#dupObject



26
27
28
29
30
# File 'lib/resourcelogic/response_collector.rb', line 26

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