Class: Mongrep::QueryResult
- Inherits:
-
Object
- Object
- Mongrep::QueryResult
- Includes:
- Enumerable
- Defined in:
- lib/mongrep/query_result.rb
Overview
A wrapper around mongo cursors
Constant Summary collapse
- DELEGATED_METHODS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The methods to be delegated to the underlying mongo cursor
i(limit projection skip sort).freeze
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
Instance Method Summary collapse
-
#count ⇒ Integer
The amount of documents in this result.
-
#each {|item| ... } ⇒ void
Iterates over the query result.
-
#initialize(collection_view, &initialize_model) ⇒ QueryResult
constructor
private
A new instance of QueryResult.
Constructor Details
#initialize(collection_view, &initialize_model) ⇒ QueryResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of QueryResult.
13 14 15 16 |
# File 'lib/mongrep/query_result.rb', line 13 def initialize(collection_view, &initialize_model) @initialize_model = initialize_model @collection_view = collection_view end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
11 12 13 |
# File 'lib/mongrep/query_result.rb', line 11 def model_class @model_class end |
Instance Method Details
#count ⇒ Integer
Returns The amount of documents in this result.
33 34 35 36 37 |
# File 'lib/mongrep/query_result.rb', line 33 def count @collection_view.count ensure @collection_view.close_query end |
#each {|item| ... } ⇒ void
This method returns an undefined value.
Iterates over the query result
43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mongrep/query_result.rb', line 43 def each return enum_for(:each) unless block_given? begin @collection_view.each do |document| yield @initialize_model.call(document) end ensure @collection_view.close_query end end |