Class: Elasticsearch::DSL::Search::Query
- Inherits:
-
Object
- Object
- Elasticsearch::DSL::Search::Query
- Defined in:
- lib/elasticsearch/dsl/search/query.rb
Overview
Wraps the ‘query` part of a search definition
Instance Method Summary collapse
-
#call ⇒ self
Evaluates any block passed to the query.
-
#initialize(*args, &block) ⇒ Query
constructor
A new instance of Query.
-
#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 query definition to a Hash.
Constructor Details
#initialize(*args, &block) ⇒ Query
Returns a new instance of Query.
31 32 33 |
# File 'lib/elasticsearch/dsl/search/query.rb', line 31 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
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/elasticsearch/dsl/search/query.rb', line 39 def method_missing(name, *args, &block) klass = Utils.__camelize(name) if Queries.const_defined? klass @value = Queries.const_get(klass).new *args, &block elsif @block @block.binding.eval('self').send(name, *args, &block) else super end end |
Instance Method Details
#call ⇒ self
Evaluates any block passed to the query
54 55 56 57 |
# File 'lib/elasticsearch/dsl/search/query.rb', line 54 def call @block.arity < 1 ? self.instance_eval(&@block) : @block.call(self) if @block self end |
#to_hash(options = {}) ⇒ Hash
Converts the query definition to a Hash
63 64 65 66 67 68 69 70 |
# File 'lib/elasticsearch/dsl/search/query.rb', line 63 def to_hash(={}) call if @value @value.to_hash else {} end end |