Class: Zelastic::Config
- Inherits:
-
Object
- Object
- Zelastic::Config
- Defined in:
- lib/zelastic/config.rb
Instance Attribute Summary collapse
-
#clients ⇒ Object
readonly
Returns the value of attribute clients.
Instance Method Summary collapse
- #data_source ⇒ Object
- #index_data(model) ⇒ Object
- #index_definition ⇒ Object
-
#initialize(client:, data_source:, mapping:, logger: nil, **overrides, &index_data) ⇒ Config
constructor
A new instance of Config.
- #logger ⇒ Object
- #read_alias ⇒ Object
- #write_alias ⇒ Object
Constructor Details
#initialize(client:, data_source:, mapping:, logger: nil, **overrides, &index_data) ⇒ Config
Returns a new instance of Config.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zelastic/config.rb', line 7 def initialize( client:, data_source:, mapping:, logger: nil, **overrides, &index_data ) @clients = Array(client) @data_source = data_source @mapping = mapping @logger = logger @overrides = overrides @index_data = index_data end |
Instance Attribute Details
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
5 6 7 |
# File 'lib/zelastic/config.rb', line 5 def clients @clients end |
Instance Method Details
#data_source ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/zelastic/config.rb', line 27 def data_source if @data_source.respond_to? :call @data_source.call else @data_source end end |
#index_data(model) ⇒ Object
23 24 25 |
# File 'lib/zelastic/config.rb', line 23 def index_data(model) @index_data.call(model) end |
#index_definition ⇒ Object
49 50 51 52 53 54 |
# File 'lib/zelastic/config.rb', line 49 def index_definition { settings: overrides.fetch(:index_settings, {}), mappings: mapping } end |
#logger ⇒ Object
43 44 45 46 47 |
# File 'lib/zelastic/config.rb', line 43 def logger return Rails.logger if defined?(Rails) @logger ||= Logger.new($stdout) end |
#read_alias ⇒ Object
35 36 37 |
# File 'lib/zelastic/config.rb', line 35 def read_alias @read_alias ||= overrides.fetch(:read_alias) { data_source.table_name } end |
#write_alias ⇒ Object
39 40 41 |
# File 'lib/zelastic/config.rb', line 39 def write_alias @write_alias ||= overrides.fetch(:write_alias) { [read_alias, 'write'].join('_') } end |