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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 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
  @_type = overrides.fetch(:type, true)
  @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



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

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

#index_definitionObject



48
49
50
51
52
53
# File 'lib/zelastic/config.rb', line 48

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

#loggerObject



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

def logger
  return Rails.logger if defined?(Rails)

  @logger ||= Logger.new(STDOUT)
end

#read_aliasObject



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

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

#typeObject



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

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

#type?Boolean



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

def type?
  @_type
end

#write_aliasObject



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

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