Class: Zelastic::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/zelastic/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client:, data_source:, mapping:, **overrides, &index_data) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/zelastic/config.rb', line 7

def initialize(
  client:,
  data_source:,
  mapping:,
  **overrides,
  &index_data
)
  @clients = Array(client)
  @data_source = data_source
  @mapping = mapping
  @index_data = index_data
  @overrides = overrides
end

Instance Attribute Details

#clientsObject (readonly)

Returns the value of attribute clients.



5
6
7
# File 'lib/zelastic/config.rb', line 5

def clients
  @clients
end

#data_sourceObject (readonly)

Returns the value of attribute data_source.



5
6
7
# File 'lib/zelastic/config.rb', line 5

def data_source
  @data_source
end

Instance Method Details

#index_data(model) ⇒ Object



21
22
23
# File 'lib/zelastic/config.rb', line 21

def index_data(model)
  @index_data.call(model)
end

#index_definitionObject



42
43
44
45
46
47
# File 'lib/zelastic/config.rb', line 42

def index_definition
  {
    settings: overrides.fetch(:index_settings, {}),
    mappings: { type => mapping }
  }
end

#loggerObject



37
38
39
40
# File 'lib/zelastic/config.rb', line 37

def logger
  return Rails.logger if defined?(Rails)
  @logger ||= Logger.new(STDOUT)
end

#read_aliasObject



25
26
27
# File 'lib/zelastic/config.rb', line 25

def read_alias
  @read_alias ||= overrides.fetch(:read_alias) { data_source.table_name }
end

#typeObject



33
34
35
# File 'lib/zelastic/config.rb', line 33

def type
  @type ||= overrides.fetch(:type, read_alias.singularize)
end

#write_aliasObject



29
30
31
# File 'lib/zelastic/config.rb', line 29

def write_alias
  @write_alias ||= overrides.fetch(:write_alias) { [read_alias, 'write'].join('_') }
end