module Elasticsearch::DSL::Search::BaseComponent::InstanceMethods

Public Instance Methods

call() click to toggle source

Evaluates any block passed to the query

@return [self]

# File lib/elasticsearch/dsl/search/base_component.rb, line 143
def call
  if @block
    @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self)
  end
  self
end
empty?() click to toggle source

Return true when the component definition is empty

# File lib/elasticsearch/dsl/search/base_component.rb, line 152
def empty?
  to_hash[name].respond_to?(:empty?) && to_hash[name].empty?
end
name() click to toggle source

Return the name for instance of the DSL class

@return [String]

# File lib/elasticsearch/dsl/search/base_component.rb, line 135
def name
  self.class.name
end
to_hash(options={}) click to toggle source

Convert the query definition to a Hash

A default implementation, DSL classes can overload it.

@return [Hash]

# File lib/elasticsearch/dsl/search/base_component.rb, line 162
def to_hash(options={})
  case
    # 1. Create hash from the block
    when @block
      @hash = (@args && ! @args.empty?) ? { name => { @args => {} } } : { name => {} }
      call
      @hash[self.name.to_sym].update @options unless @options.empty?
      @hash
    # 2. Hash created with option methods
    when @hash[self.name.to_sym] && ! @args.is_a?(Hash) && @hash[self.name.to_sym][@args]
      @hash[self.name.to_sym].update @options unless @options.empty?
      @hash
    # 3. Hash passsed as @args
    when @hash[self.name.to_sym] && @args.respond_to?(:to_hash) && ! @args.empty?
      { name => @args.to_hash }
    # 4. Hash already built
    else
      @hash
  end
end

Private Instance Methods

method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/elasticsearch/dsl/search/base_component.rb, line 185
def method_missing(name, *args, &block)
  if @block
    @block.binding.eval('self').send(name, *args, &block)
  else
    super
  end
end