@@ -141,12 +141,12 @@ def hint=(hint=nil)
141
141
# @option opts [Array] :sort an array of [key, direction] pairs to sort by. Direction should
142
142
# be specified as Mongo::ASCENDING (or :ascending / :asc) or Mongo::DESCENDING (or :descending / :desc)
143
143
# @option opts [String, Array, OrderedHash] :hint hint for query optimizer, usually not necessary if using MongoDB > 1.1
144
- # @option opts [Boolean] :snapshot (' false' ) if true, snapshot mode will be used for this query.
144
+ # @option opts [Boolean] :snapshot (false) if true, snapshot mode will be used for this query.
145
145
# Snapshot mode assures no duplicates are returned, or objects missed, which were preset at both the start and
146
146
# end of the query's execution. For details see http://www.mongodb.org/display/DOCS/How+to+do+Snapshotting+in+the+Mongo+Database
147
147
# @option opts [Boolean] :batch_size (100) the number of documents to returned by the database per GETMORE operation. A value of 0
148
148
# will let the database server decide how many results to returns. This option can be ignored for most use cases.
149
- # @option opts [Boolean] :timeout (' true' ) when +true+, the returned cursor will be subject to
149
+ # @option opts [Boolean] :timeout (true) when +true+, the returned cursor will be subject to
150
150
# the normal cursor timeout behavior of the mongod process. When +false+, the returned cursor will never timeout. Note
151
151
# that disabling timeout will only work when #find is invoked with a block. This is to prevent any inadvertant failure to
152
152
# close the cursor, as the cursor is explicitly closed when block code finishes.
@@ -165,13 +165,12 @@ def find(selector={}, opts={})
165
165
limit = opts . delete ( :limit ) || 0
166
166
sort = opts . delete ( :sort )
167
167
hint = opts . delete ( :hint )
168
- snapshot = opts . delete ( :snapshot )
168
+ snapshot = opts . delete ( :snapshot )
169
169
batch_size = opts . delete ( :batch_size )
170
+ timeout = ( opts . delete ( :timeout ) == false ) ? false : true
170
171
171
- if opts [ :timeout ] == false && !block_given?
172
- raise ArgumentError , "Timeout can be set to false only when #find is invoked with a block."
173
- else
174
- timeout = opts . delete ( :timeout ) || false
172
+ if !timeout
173
+ raise ArgumentError , "Collection#find must be invoked with a block when timeout is disabled."
175
174
end
176
175
177
176
if hint
@@ -187,7 +186,7 @@ def find(selector={}, opts={})
187
186
188
187
if block_given?
189
188
yield cursor
190
- cursor . close ( )
189
+ cursor . close
191
190
nil
192
191
else
193
192
cursor
0 commit comments