Class: OpenSearch::DSL::Search::Aggregation
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Aggregation
- Defined in:
- lib/opensearch/dsl/search/aggregation.rb
Overview
Wraps the ‘aggregations` part of a search definition
Instance Method Summary collapse
-
#aggregation(*args, &block) ⇒ Object
Defines an aggregation nested in another one.
-
#aggregations ⇒ Object
Returns the aggregations.
-
#call ⇒ self
private
Evaluates the block passed to initializer, ensuring it is called just once.
-
#initialize(*args, &block) ⇒ Aggregation
constructor
A new instance of Aggregation.
-
#method_missing(name, *args, &block) ⇒ Object
Looks up the corresponding class for a method being invoked, and initializes it.
-
#to_hash(options = {}) ⇒ Hash
Converts the object to a Hash.
Constructor Details
#initialize(*args, &block) ⇒ Aggregation
Returns a new instance of Aggregation.
45 46 47 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 45 def initialize(*args, &block) @block = block end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
Looks up the corresponding class for a method being invoked, and initializes it
53 54 55 56 57 58 59 60 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 53 def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Aggregations.const_defined? klass @value = Aggregations.const_get(klass).new *args, &block else raise NoMethodError, "undefined method '#{name}' for #{self}" end end |
Instance Method Details
#aggregation(*args, &block) ⇒ Object
Defines an aggregation nested in another one
64 65 66 67 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 64 def aggregation(*args, &block) call @value.__send__ :aggregation, *args, &block end |
#aggregations ⇒ Object
Returns the aggregations
71 72 73 74 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 71 def aggregations call @value.__send__ :aggregations end |
#call ⇒ self
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
82 83 84 85 86 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 82 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
Converts the object to a Hash
92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/opensearch/dsl/search/aggregation.rb', line 92 def to_hash(={}) call if @value case when @value.respond_to?(:to_hash) @value.to_hash else @value end else {} end end |