Module: ApiClient::Dispatcher

Defined in:
lib/api-client/dispatcher.rb

Overview

ApiClient::Dispatcher provides methods to make requests

Defined Under Namespace

Modules: NetHttp, Typhoeus Classes: Parallel

Class Method Summary collapse

Class Method Details

.method_missing(method_name, *args) ⇒ Object

It passes the call to a more specific class to handle the dispatch logic based on the environment.

Parameters:

  • method_name (Symbol)

    the name of the method.

  • args (Array)

    array of params to be passed ahead.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/api-client/dispatcher.rb', line 11

def self.method_missing(method_name, *args)
  case true
    when ApiClient.config.hydra != false && defined?(::Typhoeus) != nil
      return Parallel.send(method_name, *args) if Parallel.respond_to?(method_name)
    when defined?(::Typhoeus)
      return Typhoeus.send(method_name, *args) if Typhoeus.respond_to?(method_name)
    else
      return NetHttp.send(method_name, *args) if NetHttp.respond_to?(method_name)
  end
  super
end

.respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Overwrite respond_to? default behavior

Parameters:

  • method_name (Symbol)

    the name of the method.

  • include_private (Boolean) (defaults to: false)

    if it does work to private methods as well.

Returns:

  • (Boolean)

    if it responds to the method or not.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/api-client/dispatcher.rb', line 28

def self.respond_to_missing?(method_name, include_private = false)
  case true
    when ApiClient.config.hydra && defined?(::Typhoeus)
      return true if Parallel.respond_to?(method_name)
    when defined?(::Typhoeus)
      return true if Typhoeus.respond_to?(method_name)
    else
      return true if NetHttp.respond_to?(method_name)
  end
  super
end