Class: OpenSearch::DSL::Search::Filter
- Inherits:
-
Object
- Object
- OpenSearch::DSL::Search::Filter
- Defined in:
- lib/opensearch/dsl/search/filter.rb
Overview
Wraps the ‘filter` part of a search definition, aggregation, etc
Instance Method Summary collapse
-
#call ⇒ self
Evaluates any block passed to the query.
-
#initialize(*_args, &block) ⇒ Filter
constructor
A new instance of Filter.
-
#method_missing(name, *args, &block) ⇒ Object
Looks up the corresponding class for a method being invoked, and initializes it.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#to_hash(_options = {}) ⇒ Hash
Converts the query definition to a Hash.
Constructor Details
#initialize(*_args, &block) ⇒ Filter
Returns a new instance of Filter.
38 39 40 |
# File 'lib/opensearch/dsl/search/filter.rb', line 38 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
46 47 48 49 50 |
# File 'lib/opensearch/dsl/search/filter.rb', line 46 def method_missing(name, *args, &block) klass = Utils.__camelize(name) raise NoMethodError, "undefined method '#{name}' for #{self}" unless Filters.const_defined? klass @value = Filters.const_get(klass).new(*args, &block) end |
Instance Method Details
#call ⇒ self
Evaluates any block passed to the query
60 61 62 63 64 65 |
# File 'lib/opensearch/dsl/search/filter.rb', line 60 def call if @block @block.arity < 1 ? instance_eval(&@block) : @block.call(self) end self end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
52 53 54 |
# File 'lib/opensearch/dsl/search/filter.rb', line 52 def respond_to_missing?(method_name, include_private = false) Filters.const_defined?(Utils.__camelize(method_name)) || super end |
#to_hash(_options = {}) ⇒ Hash
Converts the query definition to a Hash
71 72 73 74 75 76 77 78 |
# File 'lib/opensearch/dsl/search/filter.rb', line 71 def to_hash( = {}) call if @value @value.to_hash else {} end end |