Class: Mongoid::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/mongoid/cursor.rb
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.
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 ⇒ Object
Return the next document in the cursor.
-
#to_a ⇒ Object
Returns an array of all the documents in the cursor.
Constructor Details
#initialize(klass, collection, cursor) ⇒ Cursor
Create the new Mongoid::Cursor
.
Options:
collection: The Mongoid::Collection instance. cursor: The Mongo::Cursor to be proxied.
Example:
Mongoid::Cursor.new(Person, cursor)
58 59 60 |
# File 'lib/mongoid/cursor.rb', line 58 def initialize(klass, collection, cursor) @klass, @collection, @cursor = klass, collection, cursor end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
26 27 28 |
# File 'lib/mongoid/cursor.rb', line 26 def collection @collection end |
Instance Method Details
#each ⇒ Object
Iterate over each document in the cursor and yield to it.
Example:
cursor.each { |doc| p doc.title }
42 43 44 45 46 |
# File 'lib/mongoid/cursor.rb', line 42 def each @cursor.each do |document| yield Mongoid::Factory.build(@klass, document) end end |