Module: Metacrunch::Elasticsearch::OptionsHelpers

Included in:
IndexCreator, Indexer, Searcher
Defined in:
lib/metacrunch/elasticsearch/options_helpers.rb

Instance Method Summary collapse

Instance Method Details

#extract_options!(options, *keys) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/metacrunch/elasticsearch/options_helpers.rb', line 4

def extract_options!(options, *keys)
  keys = keys
  .map do |_key|
    _key == :_client_options_ ? [:host, :hosts, :url, :urls] : _key
  end
  .flatten

  options
  .delete_if do |_key, _value|
    if keys.include?(_key)
      instance_variable_set("@#{_key}", _value)
      true # else if _value is falsy, the key does not get deleted
    end
  end
end

#normalize_options!(options) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/metacrunch/elasticsearch/options_helpers.rb', line 20

def normalize_options!(options)
  {
    index: options[:index],
    body: options.select { |_key, _| _key != :index }
  }
  .tap(&:compact!)
  .try do |_result|
    options.clear.merge!(_result)
  end
end