Module: OpenSearch::DSL::Search::BaseCompoundFilterComponent::InstanceMethods

Defined in:
lib/opensearch/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)


56
57
58
59
60
# File 'lib/opensearch/dsl/search/base_compound_filter_component.rb', line 56

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)


68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/opensearch/dsl/search/base_compound_filter_component.rb', line 68

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