class Waistband::Client

Attributes

servers[R]

Public Class Methods

from_config(config_hash) click to toggle source
# 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
new(servers, options = {}) click to toggle source
# 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

Public Instance Methods

config_hash() click to toggle source
# 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
connection() click to toggle source
# File lib/waistband/client.rb, line 29
def connection
  @connection ||= Elasticsearch::Client.new config_hash
end
method_missing(method_name, *args, &block) click to toggle source
Calls superclass method
# 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

Private Instance Methods

hosts() click to toggle source
# File lib/waistband/client.rb, line 56
def hosts
  @hosts ||= @servers.map do |server_name, config|
    config.each_with_object({}) { |(key, value), obj| obj[key.to_sym] = value }
  end
end