Class: EsClient

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/rotating_es_loader/es_client.rb

Overview

:nodoc

Direct Known Subclasses

RotatingEsLoader

Instance Method Summary collapse

Constructor Details

#initialize(url:, credentials:, logger: nil) ⇒ EsClient

Returns a new instance of EsClient.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rotating_es_loader/es_client.rb', line 14

def initialize(
  url:,
  credentials:,
  logger: nil
)

  raise('credentials must be an Aws::SharedCredentials') unless \
    credentials.is_a?(Aws::SharedCredentials)

  @logger = logger || Logger.new(STDOUT)
  @url = url
  @credentials = credentials
  @logger.info('URL is ' + url)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



40
41
42
43
# File 'lib/rotating_es_loader/es_client.rb', line 40

def method_missing(m, *args, &block)
  @logger.debug("Delegating #{m}")
  client.send(m, *args, &block)
end

Instance Method Details

#clientObject



29
30
31
32
33
34
35
36
37
# File 'lib/rotating_es_loader/es_client.rb', line 29

def client
  Elasticsearch::Client.new(url: @url) do |f|
    f.use FaradayMiddleware::Gzip
    f.request :aws_signers_v4,
              credentials: @credentials,
              service_name: 'es',
              region: 'us-west-1'
  end
end