Class: TentClient::CycleHTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/tent-client/cycle_http.rb

Overview

Proxies to Faraday and cycles through server urls

until either non left or response status in the 200s or 400s

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, &faraday_block) ⇒ CycleHTTP

Returns a new instance of CycleHTTP.



7
8
9
10
11
# File 'lib/tent-client/cycle_http.rb', line 7

def initialize(client, &faraday_block)
  @faraday_block = faraday_block
  @client = client
  @server_urls = client.server_urls.dup
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



41
42
43
44
45
46
47
# File 'lib/tent-client/cycle_http.rb', line 41

def method_missing(method_name, *args, &block)
  if http.respond_to?(method_name)
    http.send(method_name, *args, &block)
  else
    super
  end
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/tent-client/cycle_http.rb', line 6

def client
  @client
end

#server_urlsObject (readonly)

Returns the value of attribute server_urls.



6
7
8
# File 'lib/tent-client/cycle_http.rb', line 6

def server_urls
  @server_urls
end

Instance Method Details

#httpObject



19
20
21
# File 'lib/tent-client/cycle_http.rb', line 19

def http
  @http || new_http
end

#new_httpObject



13
14
15
16
17
# File 'lib/tent-client/cycle_http.rb', line 13

def new_http
  @http = Faraday.new(:url => server_urls.shift) do |f|
    @faraday_block.call(f)
  end
end

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

Returns:

  • (Boolean)


37
38
39
# File 'lib/tent-client/cycle_http.rb', line 37

def respond_to_missing?(method_name, include_private = false)
  http.respond_to?(method_name, include_private)
end