Class: Elasticsearch::Model::Response::Result
- Inherits:
-
Object
- Object
- Elasticsearch::Model::Response::Result
- Defined in:
- lib/elasticsearch/model/response/result.rb
Overview
Encapsulates the “hit” returned from the Elasticsearch client
Wraps the raw Hash with in a ‘Hashie::Mash` instance, providing access to the Hash properties by calling Ruby methods.
Instance Method Summary collapse
- #as_json(options = {}) ⇒ Object
-
#initialize(attributes = {}) ⇒ Result
constructor
A new instance of Result.
-
#method_missing(method_name, *arguments) ⇒ Object
Delegate methods to ‘@result` or `@result._source`.
-
#respond_to?(method_name, include_private = false) ⇒ Boolean
Respond to methods from ‘@result` or `@result._source`.
Constructor Details
#initialize(attributes = {}) ⇒ Result
Returns a new instance of Result.
16 17 18 |
# File 'lib/elasticsearch/model/response/result.rb', line 16 def initialize(attributes={}) @result = Hashie::Mash.new(attributes) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object
Delegate methods to ‘@result` or `@result._source`
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/elasticsearch/model/response/result.rb', line 22 def method_missing(method_name, *arguments) case when @result.respond_to?(method_name.to_sym) @result.__send__ method_name.to_sym, *arguments when @result._source && @result._source.respond_to?(method_name.to_sym) @result._source.__send__ method_name.to_sym, *arguments else super end end |
Instance Method Details
#as_json(options = {}) ⇒ Object
41 42 43 |
# File 'lib/elasticsearch/model/response/result.rb', line 41 def as_json(={}) @result.as_json() end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
Respond to methods from ‘@result` or `@result._source`
35 36 37 38 39 |
# File 'lib/elasticsearch/model/response/result.rb', line 35 def respond_to?(method_name, include_private = false) @result.respond_to?(method_name.to_sym) || \ @result._source && @result._source.respond_to?(method_name.to_sym) || \ super end |