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
Attributes included from Base
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.
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/elasticsearch/model/response/records.rb', line 19 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`
57 58 59 |
# File 'lib/elasticsearch/model/response/records.rb', line 57 def method_missing(method_name, *arguments) records.respond_to?(method_name) ? records.__send__(method_name, *arguments) : super end |
Instance Method Details
#each_with_hit(&block) ⇒ Object
Yields [record, hit] pairs to the block
45 46 47 |
# File 'lib/elasticsearch/model/response/records.rb', line 45 def each_with_hit(&block) records.to_a.zip(results).each(&block) end |
#ids ⇒ Object
Returns the hit IDs
33 34 35 |
# File 'lib/elasticsearch/model/response/records.rb', line 33 def ids response.response['hits']['hits'].map { |hit| hit['_id'] } end |
#map_with_hit(&block) ⇒ Object
Yields [record, hit] pairs and returns the result
51 52 53 |
# File 'lib/elasticsearch/model/response/records.rb', line 51 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`
63 64 65 |
# File 'lib/elasticsearch/model/response/records.rb', line 63 def respond_to?(method_name, include_private = false) records.respond_to?(method_name) || super end |
#results ⇒ Object
Returns the Elasticsearch::Model::Response::Results collection
39 40 41 |
# File 'lib/elasticsearch/model/response/records.rb', line 39 def results response.results end |