Class: Waistband::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/waistband/client.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(servers, options = {}) ⇒ Client

Returns a new instance of Client.



20
21
22
23
24
25
26
27
# File 'lib/waistband/client.rb', line 20

def initialize(servers, options = {})
  @servers = servers
  @randomize_hosts = options.fetch(:randomize_hosts, true)
  @retry_on_failure = options[:retry_on_failure]
  @reload_on_failure = options[:reload_on_failure]
  @timeout = options[:timeout]
  @adapter = options[:adapter]
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



49
50
51
52
# File 'lib/waistband/client.rb', line 49

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

Instance Attribute Details

#serversObject (readonly)

Returns the value of attribute servers.



18
19
20
# File 'lib/waistband/client.rb', line 18

def servers
  @servers
end

Class Method Details

.from_config(config_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/waistband/client.rb', line 6

def from_config(config_hash)
  new(
    config_hash['servers'], randomize_hosts: true,
    retry_on_failure: config_hash['retries'],
    reload_on_failure: config_hash['reload_on_failure'],
    timeout: config_hash['timeout'],
    adapter: config_hash['adapter']
  )
end

Instance Method Details

#config_hashObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/waistband/client.rb', line 33

def config_hash
  {
    adapter: @adapter,
    hosts: hosts,
    randomize_hosts: @randomize_hosts,
    retry_on_failure: @retry_on_failure,
    reload_on_failure: @reload_on_failure,
    transport_options: {
      request: {
        open_timeout: @timeout,
        timeout: @timeout
      }
    }
  }
end

#connectionObject



29
30
31
# File 'lib/waistband/client.rb', line 29

def connection
  @connection ||= Elasticsearch::Client.new config_hash
end