Class: Faraday::ForTest::Proxy

Inherits:
BasicObject
Defined in:
lib/faraday/for_test/proxy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection) ⇒ Proxy

Returns a new instance of Proxy.



5
6
7
# File 'lib/faraday/for_test/proxy.rb', line 5

def initialize(connection)
  @connection = connection
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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

proxy every method



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/faraday/for_test/proxy.rb', line 10

def method_missing(name, *args, &block)
  if @connection.respond_to?(name)
    maybe_response = @connection.__send__(name, *args, &block)

    if maybe_response.is_a?(::Faraday::Response)
      request_params = args.find {|e| e.is_a?(::Array) || e.is_a?(::Hash) || e.is_a?(::NilClass) }

      # TODO: configurable to find out request_params from args
      ::Faraday::ForTest::Response.new(maybe_response, request_params: request_params)
    else
      maybe_response
    end
  else
    super
  end
end

Instance Attribute Details

#connectionObject (readonly)

Returns the value of attribute connection.



3
4
5
# File 'lib/faraday/for_test/proxy.rb', line 3

def connection
  @connection
end