From 6a43aaa94f5e888798543e6c82bfae15d57a63c0 Mon Sep 17 00:00:00 2001 From: Mike Dirolf Date: Fri, 21 Aug 2009 11:21:33 -0400 Subject: [PATCH] minor: doc --- lib/mongo/cursor.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index 3df7bb5..ca55b3b 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -1,4 +1,3 @@ -# -- # Copyright (C) 2008-2009 10gen Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -12,7 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -# ++ require 'mongo/message' require 'mongo/util/byte_buffer' @@ -29,6 +27,9 @@ module Mongo attr_reader :db, :collection, :query + # Create a new cursor. + # + # Should not be called directly by application developers. def initialize(db, collection, query, admin=false) @db, @collection, @query, @admin = db, collection, query, admin @num_to_return = @query.number_to_return || 0 @@ -39,8 +40,6 @@ module Mongo @rows = nil end - def closed?; @closed; end - # Return the next object or nil if there are no more. Raises an error # if necessary. def next_object @@ -125,7 +124,7 @@ module Mongo @rows end - # Returns an explain plan record. + # Returns an explain plan record for this cursor. def explain old_val = @query.explain @query.explain = true @@ -143,6 +142,10 @@ module Mongo # Note: if a cursor is read until exhausted (read until OP_QUERY or # OP_GETMORE returns zero for the cursor id), there is no need to # close it by calling this method. + # + # Collection#find takes an optional block argument which can be used to + # ensure that your cursors get closed. See the documentation for + # Collection#find for details. def close @db.send_to_db(KillCursorsMessage.new(@cursor_id)) if @cursor_id @cache = [] @@ -150,6 +153,9 @@ module Mongo @closed = true end + # Returns true if this cursor is closed, false otherwise. + def closed?; @closed; end + private def read_all