Mongoid wrapper of the Ruby Driver cursor.
Operations on the Mongo::Cursor object that will not get overriden by the Mongoid::Cursor are defined here.
Iterate over each document in the cursor and yield to it.
@example Iterate over the cursor.
cursor.each { |doc| p doc.title }
# File lib/mongoid/cursor.rb, line 46 def each cursor.each do |document| yield Mongoid::Factory.from_db(klass, document) end end
Return the next document in the cursor. Will instantiate a new Mongoid document with the attributes.
@example Get the next document.
cursor.next_document
@return [ Document ] The next document in the cursor.
# File lib/mongoid/cursor.rb, line 71 def next_document Mongoid::Factory.from_db(klass, cursor.next_document) end
Returns an array of all the documents in the cursor.
@example Get the cursor as an array.
cursor.to_a
@return [ Array<Document> ] An array of documents.
# File lib/mongoid/cursor.rb, line 81 def to_a cursor.to_a.collect { |attrs| Mongoid::Factory.from_db(klass, attrs) } end
Create the new +Mongoid::Cursor+.
@example Instantiate the cursor.
Mongoid::Cursor.new(Person, cursor)
@param [ Class ] klass The class associated with the cursor. @param [ Collection ] collection The Mongoid::Collection instance. @param [ Mongo::Cursor ] cursor The Mongo::Cursor to be proxied.
# File lib/mongoid/cursor.rb, line 60 def initialize(klass, collection, cursor) @klass, @collection, @cursor = klass, collection, cursor end
Generated with the Darkfish Rdoc Generator 2.