Class: Runcible::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/runcible/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parsed_body, rest_client_response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/runcible/response.rb', line 5

def initialize(parsed_body, rest_client_response)
  @rest_client_response = rest_client_response
  @parsed_body = parsed_body
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/runcible/response.rb', line 30

def method_missing(name, *args, &block)
  if @parsed_body.respond_to?(name)
    @parsed_body.send(name, *args, &block)
  elsif @rest_client_response.respond_to?(name)
    @rest_client_response.send(name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#parsed_bodyObject

Returns the value of attribute parsed_body.



3
4
5
# File 'lib/runcible/response.rb', line 3

def parsed_body
  @parsed_body
end

#rest_client_responseObject

Returns the value of attribute rest_client_response.



3
4
5
# File 'lib/runcible/response.rb', line 3

def rest_client_response
  @rest_client_response
end

Instance Method Details

#==(other) ⇒ Object



14
15
16
# File 'lib/runcible/response.rb', line 14

def ==(other)
  self.parsed_body == other
end

#bodyObject



22
23
24
# File 'lib/runcible/response.rb', line 22

def body
  @parsed_body
end

#is_a?(clazz) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/runcible/response.rb', line 18

def is_a?(clazz)
  self.parsed_body.is_a?(clazz)
end

#respond_to?(name) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/runcible/response.rb', line 10

def respond_to?(name)
  @parsed_body.respond_to?(name) || @rest_client_response.respond_to?(name)
end

#to_hashObject



26
27
28
# File 'lib/runcible/response.rb', line 26

def to_hash
  self.parsed_body.try(:to_hash)
end