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.
-
#data_source ⇒ Object
readonly
Returns the value of attribute data_source.
Instance Method Summary collapse
- #index_data(model) ⇒ Object
- #index_definition ⇒ Object
-
#initialize(client:, data_source:, mapping:, **overrides, &index_data) ⇒ Config
constructor
A new instance of Config.
- #logger ⇒ Object
- #read_alias ⇒ Object
- #type ⇒ Object
- #write_alias ⇒ Object
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
#clients ⇒ Object (readonly)
Returns the value of attribute clients.
5 6 7 |
# File 'lib/zelastic/config.rb', line 5 def clients @clients end |
#data_source ⇒ Object (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_definition ⇒ Object
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 |
#logger ⇒ Object
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_alias ⇒ Object
25 26 27 |
# File 'lib/zelastic/config.rb', line 25 def read_alias @read_alias ||= overrides.fetch(:read_alias) { data_source.table_name } end |
#type ⇒ Object
33 34 35 |
# File 'lib/zelastic/config.rb', line 33 def type @type ||= overrides.fetch(:type, read_alias.singularize) end |
#write_alias ⇒ Object
29 30 31 |
# File 'lib/zelastic/config.rb', line 29 def write_alias @write_alias ||= overrides.fetch(:write_alias) { [read_alias, 'write'].join('_') } end |