Class: Elasticsearch::Model::Response::Records
- Inherits:
-
Object
- Object
- Elasticsearch::Model::Response::Records
- Includes:
- Base, Enumerable
- Defined in:
- lib/elasticsearch/model/response/records.rb
Overview
Encapsulates the collection of records returned from the database
Implements Enumerable and forwards its methods to the Base#records object, which is provided by an Adapter::Adapter implementation.
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Attributes included from Base
#klass, #raw_response, #response
Instance Method Summary collapse
-
#each_with_hit(&block) ⇒ Object
Yields [record, hit] pairs to the block.
-
#ids ⇒ Object
Returns the hit IDs.
-
#initialize(klass, response, options = {}) ⇒ Records
constructor
A new instance of Records.
-
#map_with_hit(&block) ⇒ Object
Yields [record, hit] pairs and returns the result.
-
#method_missing(method_name, *arguments) ⇒ Object
Delegate methods to ‘@records`.
-
#respond_to?(method_name, include_private = false) ⇒ Boolean
Respond to methods from ‘@records`.
-
#results ⇒ Object
Returns the Results collection.
Methods included from Base
Constructor Details
#initialize(klass, response, options = {}) ⇒ Records
Returns a new instance of Records.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/elasticsearch/model/response/records.rb', line 38 def initialize(klass, response, ={}) super # Include module provided by the adapter in the singleton class ("metaclass") # adapter = Adapter.from_class(klass) = class << self; self; end .__send__ :include, adapter.records_mixin self. = end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments) ⇒ Object
Delegate methods to ‘@records`
76 77 78 |
# File 'lib/elasticsearch/model/response/records.rb', line 76 def method_missing(method_name, *arguments) records.respond_to?(method_name) ? records.__send__(method_name, *arguments) : super end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
32 33 34 |
# File 'lib/elasticsearch/model/response/records.rb', line 32 def @options end |
Instance Method Details
#each_with_hit(&block) ⇒ Object
Yields [record, hit] pairs to the block
64 65 66 |
# File 'lib/elasticsearch/model/response/records.rb', line 64 def each_with_hit(&block) records.to_a.zip(results).each(&block) end |
#ids ⇒ Object
Returns the hit IDs
52 53 54 |
# File 'lib/elasticsearch/model/response/records.rb', line 52 def ids response.response['hits']['hits'].map { |hit| hit['_id'] } end |
#map_with_hit(&block) ⇒ Object
Yields [record, hit] pairs and returns the result
70 71 72 |
# File 'lib/elasticsearch/model/response/records.rb', line 70 def map_with_hit(&block) records.to_a.zip(results).map(&block) end |
#respond_to?(method_name, include_private = false) ⇒ Boolean
Respond to methods from ‘@records`
82 83 84 |
# File 'lib/elasticsearch/model/response/records.rb', line 82 def respond_to?(method_name, include_private = false) records.respond_to?(method_name) || super end |
#results ⇒ Object
Returns the Elasticsearch::Model::Response::Results collection
58 59 60 |
# File 'lib/elasticsearch/model/response/records.rb', line 58 def results response.results end |