Project

General

Profile

Download (870 Bytes) Statistics
| Branch: | Tag: | Revision:

runcible / lib / runcible / response.rb @ df1b6e2a

1
module Runcible
2
  class Response
3
    attr_accessor :rest_client_response, :parsed_body
4

    
5
    def initialize(parsed_body, rest_client_response)
6
      @rest_client_response = rest_client_response
7
      @parsed_body = parsed_body
8
    end
9

    
10
    def respond_to?(name)
11
      @parsed_body.respond_to?(name) || @rest_client_response.respond_to?(name)
12
    end
13

    
14
    def ==(other)
15
      self.parsed_body == other
16
    end
17

    
18
    def is_a?(clazz)
19
      self.parsed_body.is_a?(clazz)
20
    end
21

    
22
    def body
23
      @parsed_body
24
    end
25

    
26
    def to_hash
27
      self.parsed_body.try(:to_hash)
28
    end
29

    
30
    def method_missing(name, *args, &block)
31
      if @parsed_body.respond_to?(name)
32
        @parsed_body.send(name, *args, &block)
33
      elsif @rest_client_response.respond_to?(name)
34
        @rest_client_response.send(name, *args, &block)
35
      else
36
        super
37
      end
38
    end
39
  end
40
end