Module: Elasticsearch::DSL::Search::BaseCompoundFilterComponent::InstanceMethods

Defined in:
lib/elasticsearch/dsl/search/base_compound_filter_component.rb

Overview

Common functionality for the compound filter components

Instance Method Summary collapse

Instance Method Details

#callself

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Evaluates the block passed to initializer, ensuring it is called just once

Returns:

  • (self)


34
35
36
37
38
# File 'lib/elasticsearch/dsl/search/base_compound_filter_component.rb', line 34

def call
  @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block && ! @_block_called
  @_block_called = true
  self
end

#to_hash(options = {}) ⇒ Hash

Convert the component to a Hash

A default implementation, DSL classes can overload it.

Returns:

  • (Hash)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/elasticsearch/dsl/search/base_compound_filter_component.rb', line 46

def to_hash(options={})
  case
  when @value.empty? && ! @block
    @hash = super
  when @block
    call
    @hash = { name.to_sym => @value.map { |i| i.to_hash } }
  else
    @hash = { name.to_sym => @value }
  end
  @hash
end