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.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/elasticsearch/model/response/records.rb', line 21 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. = 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`
60 61 62 |
# File 'lib/elasticsearch/model/response/records.rb', line 60 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.
15 16 17 |
# File 'lib/elasticsearch/model/response/records.rb', line 15 def @options end |
Instance Method Details
#each_with_hit(&block) ⇒ Object
Yields [record, hit] pairs to the block
48 49 50 |
# File 'lib/elasticsearch/model/response/records.rb', line 48 def each_with_hit(&block) records.to_a.zip(results).each(&block) end |
#ids ⇒ Object
Returns the hit IDs
36 37 38 |
# File 'lib/elasticsearch/model/response/records.rb', line 36 def ids response.response['hits']['hits'].map { |hit| hit['_id'] } end |
#map_with_hit(&block) ⇒ Object
Yields [record, hit] pairs and returns the result
54 55 56 |
# File 'lib/elasticsearch/model/response/records.rb', line 54 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`
66 67 68 |
# File 'lib/elasticsearch/model/response/records.rb', line 66 def respond_to?(method_name, include_private = false) records.respond_to?(method_name) || super end |
#results ⇒ Object
Returns the Elasticsearch::Model::Response::Results collection
42 43 44 |
# File 'lib/elasticsearch/model/response/records.rb', line 42 def results response.results end |