Class: Mongoid::Cursor
- Includes:
- Enumerable, Mongoid::Collections::Retry
- Defined in:
- lib/mongoid/cursor.rb
Overview
Mongoid wrapper of the Ruby Driver cursor.
Constant Summary collapse
- OPERATIONS =
Operations on the Mongo::Cursor object that will not get overriden by the Mongoid::Cursor are defined here.
[ :close, :closed?, :count, :explain, :fields, :full_collection_name, :hint, :limit, :order, :query_options_hash, :query_opts, :selector, :skip, :snapshot, :sort, :timeout ]
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#cursor ⇒ Object
readonly
Returns the value of attribute cursor.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate over each document in the cursor and yield to it.
-
#initialize(klass, collection, cursor) ⇒ Cursor
constructor
Create the new
Mongoid::Cursor
. -
#next_document ⇒ Document
Return the next document in the cursor.
-
#to_a ⇒ Array<Document>
Returns an array of all the documents in the cursor.
Methods included from Mongoid::Collections::Retry
Constructor Details
#initialize(klass, collection, cursor) ⇒ Cursor
Create the new Mongoid::Cursor
.
61 62 63 |
# File 'lib/mongoid/cursor.rb', line 61 def initialize(klass, collection, cursor) @klass, @collection, @cursor = klass, collection, cursor end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
30 31 32 |
# File 'lib/mongoid/cursor.rb', line 30 def collection @collection end |
#cursor ⇒ Object (readonly)
Returns the value of attribute cursor.
30 31 32 |
# File 'lib/mongoid/cursor.rb', line 30 def cursor @cursor end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
30 31 32 |
# File 'lib/mongoid/cursor.rb', line 30 def klass @klass end |
Instance Method Details
#each ⇒ Object
Iterate over each document in the cursor and yield to it.
47 48 49 50 51 |
# File 'lib/mongoid/cursor.rb', line 47 def each cursor.each do |document| yield Mongoid::Factory.from_db(klass, document) end end |