Skip to content

Commit 4a45d12

Browse files
committed
Fix typos and documentation
1 parent 911be01 commit 4a45d12

File tree

8 files changed

+90
-66
lines changed

8 files changed

+90
-66
lines changed

lib/mongo/collection.rb

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def drop
136136
# @option options [ Integer ] :limit The max number of docs to return from the query.
137137
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the query
138138
# to run in milliseconds.
139-
# @option options [ Hash ] :modifiers Meta-operators modifying the output or behavior
140-
# of a query.
139+
# @option options [ Hash ] :modifiers A document containing meta-operators modifying the
140+
# output or behavior of a query.
141141
# @option options [ true, false ] :no_cursor_timeout The server normally times out idle
142142
# cursors after an inactivity period (10 minutes) to prevent excess memory use.
143143
# Set this option to prevent that.
@@ -335,17 +335,17 @@ def delete_many(filter = nil)
335335
# collection.replace_one({ name: 'test' }, { name: 'test1' })
336336
#
337337
# @param [ Hash ] filter The filter to use.
338-
# @param [ Hash ] document The document to replace.
339-
# @param [ Hash ] opts The options.
338+
# @param [ Hash ] replacement The replacement document..
339+
# @param [ Hash ] options The options.
340340
#
341-
# @option opts [ true, false ] :upsert Whether to upsert if the
341+
# @option options [ true, false ] :upsert Whether to upsert if the
342342
# document doesn't exist.
343343
#
344344
# @return [ Result ] The response from the database.
345345
#
346346
# @since 2.1.0
347-
def replace_one(filter, document, opts = {})
348-
find(filter).replace_one(document, opts)
347+
def replace_one(filter, replacement, options = {})
348+
find(filter).replace_one(replacement, options)
349349
end
350350

351351
# Update documents in the collection.
@@ -355,16 +355,16 @@ def replace_one(filter, document, opts = {})
355355
#
356356
# @param [ Hash ] filter The filter to use.
357357
# @param [ Hash ] update The update statement.
358-
# @param [ Hash ] opts The options.
358+
# @param [ Hash ] options The options.
359359
#
360-
# @option opts [ true, false ] :upsert Whether to upsert if the
360+
# @option options [ true, false ] :upsert Whether to upsert if the
361361
# document doesn't exist.
362362
#
363363
# @return [ Result ] The response from the database.
364364
#
365365
# @since 2.1.0
366-
def update_many(filter, update, opts = {})
367-
find(filter).update_many(update, opts)
366+
def update_many(filter, update, options = {})
367+
find(filter).update_many(update, options)
368368
end
369369

370370
# Update a single document in the collection.
@@ -374,16 +374,16 @@ def update_many(filter, update, opts = {})
374374
#
375375
# @param [ Hash ] filter The filter to use.
376376
# @param [ Hash ] update The update statement.
377-
# @param [ Hash ] opts The options.
377+
# @param [ Hash ] options The options.
378378
#
379-
# @option opts [ true, false ] :upsert Whether to upsert if the
379+
# @option options [ true, false ] :upsert Whether to upsert if the
380380
# document doesn't exist.
381381
#
382382
# @return [ Result ] The response from the database.
383383
#
384384
# @since 2.1.0
385-
def update_one(filter, update, opts = {})
386-
find(filter).update_one(update, opts)
385+
def update_one(filter, update, options = {})
386+
find(filter).update_one(update, options)
387387
end
388388

389389
# Finds a single document in the database via findAndModify and deletes
@@ -393,75 +393,75 @@ def update_one(filter, update, opts = {})
393393
# collection.find_one_and_delete(name: 'test')
394394
#
395395
# @param [ Hash ] filter The filter to use.
396-
# @param [ Hash ] opts The options.
396+
# @param [ Hash ] options The options.
397397
#
398-
# @option opts [ Integer ] :max_time_ms The maximum amount of time to allow the command
398+
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
399399
# to run in milliseconds.
400-
# @option options [ Hash ] :projection The fields to include or exclude from each doc
401-
# in the result set.
400+
# @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
402401
# @option options [ Hash ] :sort The key and direction pairs by which the result set
403402
# will be sorted.
404403
#
405404
# @return [ BSON::Document, nil ] The document, if found.
406405
#
407406
# @since 2.1.0
408-
def find_one_and_delete(filter, opts = {})
409-
find(filter, opts).find_one_and_delete
407+
def find_one_and_delete(filter, options = {})
408+
find(filter, options).find_one_and_delete
410409
end
411410

412-
# Finds a single document via findAndModify and updates it.
411+
# Finds a single document via findAndModify and updates it, returning the original doc unless
412+
# otherwise specified.
413413
#
414414
# @example Find a document and update it, returning the original.
415-
# collection.find_one_and_update({ name: 'test' }, { "$set" => { name: 'test1' }}, :return_document => :before)
415+
# collection.find_one_and_update({ name: 'test' }, { "$set" => { name: 'test1' }})
416+
#
417+
# @example Find a document and update it, returning the updated document.
418+
# collection.find_one_and_update({ name: 'test' }, { "$set" => { name: 'test1' }}, :return_document => :after)
416419
#
417420
# @param [ Hash ] filter The filter to use.
418421
# @param [ BSON::Document ] update The update statement.
419-
# @param [ Hash ] opts The options.
422+
# @param [ Hash ] options The options.
420423
#
421-
# @option opts [ Integer ] :max_time_ms The maximum amount of time to allow the command
424+
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
422425
# to run in milliseconds.
423-
# @option options [ Hash ] :projection The fields to include or exclude from each doc
424-
# in the result set.
426+
# @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
425427
# @option options [ Hash ] :sort The key and direction pairs by which the result set
426428
# will be sorted.
427-
# @option opts [ Symbol ] :return_document Either :before or :after.
428-
# @option opts [ true, false ] :upsert Whether to upsert if the
429-
# document doesn't exist.
429+
# @option options [ Symbol ] :return_document Either :before or :after.
430+
# @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
430431
#
431432
# @return [ BSON::Document ] The document.
432433
#
433434
# @since 2.1.0
434-
def find_one_and_update(filter, update, opts = {})
435-
find(filter, opts).find_one_and_update(update, opts)
435+
def find_one_and_update(filter, update, options = {})
436+
find(filter, options).find_one_and_update(update, options)
436437
end
437438

438-
# Finds a single document and replaces it.
439+
# Finds a single document and replaces it, returning the original doc unless
440+
# otherwise specified.
439441
#
440442
# @example Find a document and replace it, returning the original.
441-
# collection.find_one_and_replace({ name: 'test' }, { name: 'test1' }, :return_document => :before)
443+
# collection.find_one_and_replace({ name: 'test' }, { name: 'test1' })
442444
#
443445
# @example Find a document and replace it, returning the new document.
444446
# collection.find_one_and_replace({ name: 'test' }, { name: 'test1' }, :return_document => :after)
445447
#
446448
# @param [ Hash ] filter The filter to use.
447449
# @param [ BSON::Document ] replacement The replacement document.
448-
# @param [ Hash ] opts The options.
450+
# @param [ Hash ] options The options.
449451
#
450-
# @option opts [ Integer ] :max_time_ms The maximum amount of time to allow the command
452+
# @option options [ Integer ] :max_time_ms The maximum amount of time to allow the command
451453
# to run in milliseconds.
452-
# @option options [ Hash ] :projection The fields to include or exclude from each doc
453-
# in the result set.
454+
# @option options [ Hash ] :projection The fields to include or exclude in the returned doc.
454455
# @option options [ Hash ] :sort The key and direction pairs by which the result set
455456
# will be sorted.
456-
# @option opts [ Symbol ] :return_document Either :before or :after.
457-
# @option opts [ true, false ] :upsert Whether to upsert if the
458-
# document doesn't exist.
457+
# @option options [ Symbol ] :return_document Either :before or :after.
458+
# @option options [ true, false ] :upsert Whether to upsert if the document doesn't exist.
459459
#
460460
# @return [ BSON::Document ] The document.
461461
#
462462
# @since 2.1.0
463-
def find_one_and_replace(filter, replacement, opts = {})
464-
find(filter, opts).find_one_and_update(replacement, opts)
463+
def find_one_and_replace(filter, replacement, options = {})
464+
find(filter, options).find_one_and_update(replacement, options)
465465
end
466466

467467
# Get the fully qualified namespace of the collection.

lib/mongo/collection/view/readable.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module Readable
4040
# Options to cursor flags mapping.
4141
#
4242
# @since 2.1.0
43-
CURSOR_FLAGS = {
43+
CURSOR_FLAGS_MAP = {
4444
:allow_partial_results => [ :partial ],
4545
:oplog_replay => [ :oplog_replay ],
4646
:no_cursor_timeout => [ :no_cursor_timeout ],
@@ -392,12 +392,11 @@ def default_read(read = nil)
392392
end
393393

394394
def flags
395-
@flags ||= (!primary? ? [ :slave_ok ] : []).tap do |flags|
396-
CURSOR_FLAGS.each do |key, value|
397-
if options[key] || (options[:cursor_type] && options[:cursor_type] == key)
398-
flags.push(*value)
399-
end
395+
@flags ||= CURSOR_FLAGS_MAP.each.reduce([]) do |flags, (key, value)|
396+
if options[key] || (options[:cursor_type] && options[:cursor_type] == key)
397+
flags.push(*value)
400398
end
399+
flags
401400
end
402401
end
403402

@@ -406,10 +405,6 @@ def has_special_fields?
406405
show_disk_loc || snapshot || explained? || cluster.sharded?
407406
end
408407

409-
def primary?
410-
read.name == :primary
411-
end
412-
413408
def query_options
414409
{ :project => projection, :skip => skip, :limit => to_return, :flags => flags }
415410
end

lib/mongo/collection/view/writable.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def delete_one
114114
# @example Replace a single document.
115115
# collection_view.replace_one({ name: 'test' })
116116
#
117-
# @param [ Hash ] document The document to replace.
117+
# @param [ Hash ] replacement The replacement document.
118118
# @param [ Hash ] opts The options.
119119
#
120120
# @option opts [ true, false ] :upsert Whether to upsert if the
@@ -123,8 +123,8 @@ def delete_one
123123
# @return [ Result ] The response from the database.
124124
#
125125
# @since 2.0.0
126-
def replace_one(document, opts = {})
127-
update(document, false, opts)
126+
def replace_one(replacement, opts = {})
127+
update(replacement, false, opts)
128128
end
129129

130130
# Update documents in the collection.

lib/mongo/event/description_changed.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def initialize(cluster)
4242
# @example Handle the event.
4343
# server_added.handle('127.0.0.1:27018')
4444
#
45-
# @param [ Address ] address The added host.
45+
# @param [ Server::Description ] updated The changed description.
4646
#
4747
# @since 2.0.0
4848
def handle(updated)

lib/mongo/operation/parallel_scan.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ module Operation
2626
# :cursor_count => 5
2727
# })
2828
#
29-
# @param [ Hash ] spec The specifications for the operation.
29+
# Initialization:
30+
# param [ Hash ] spec The specifications for the operation.
3031
#
31-
# @option spec :db_name [ String ] The name of the database on which
32-
# the operation should be executed.
33-
# @option spec :coll_name [ String ] The collection to scan.
34-
# @option spec :cursor_count [ Integer ] The number of cursors to use.
35-
# @option spec :options [ Hash ] Options for the command.
32+
# option spec :db_name [ String ] The name of the database on which
33+
# the operation should be executed.
34+
# option spec :coll_name [ String ] The collection to scan.
35+
# option spec :cursor_count [ Integer ] The number of cursors to use.
36+
# option spec :options [ Hash ] Options for the command.
3637
#
3738
# @since 2.0.0
3839
class ParallelScan
@@ -46,7 +47,7 @@ class ParallelScan
4647
# @example Execute the operation.
4748
# operation.execute(context)
4849
#
49-
# @params [ Mongo::Server::Context ] The context for this operation.
50+
# @param [ Mongo::Server::Context ] context The context for this operation.
5051
#
5152
# @return [ Result ] The operation response, if there is one.
5253
#

spec/mongo/collection/view_spec.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@
254254
{ :snapshot => true }
255255
end
256256

257+
before do
258+
expect(view).to receive(:special_selector).and_call_original
259+
end
260+
257261
it 'creates a special query selector' do
258262
expect(query_spec[:selector][:$snapshot]).to eq(options[:snapshot])
259263
end
@@ -271,6 +275,10 @@
271275
{ :max_scan => 100 }
272276
end
273277

278+
before do
279+
expect(view).to receive(:special_selector).and_call_original
280+
end
281+
274282
it 'creates a special query selector' do
275283
expect(query_spec[:selector][:$maxScan]).to eq(options[:max_scan])
276284
end
@@ -288,6 +296,10 @@
288296
{ :max_time_ms => 100 }
289297
end
290298

299+
before do
300+
expect(view).to receive(:special_selector).and_call_original
301+
end
302+
291303
it 'creates a special query selector' do
292304
expect(query_spec[:selector][:$maxTimeMS]).to eq(options[:max_time_ms])
293305
end
@@ -305,6 +317,10 @@
305317
{ :show_disk_loc => true }
306318
end
307319

320+
before do
321+
expect(view).to receive(:special_selector).and_call_original
322+
end
323+
308324
it 'creates a special query selector' do
309325
expect(query_spec[:selector][:$showDiskLoc]).to eq(options[:show_disk_loc])
310326
end
@@ -323,6 +339,10 @@
323339
{ :sort => {'x' => Mongo::Index::ASCENDING }}
324340
end
325341

342+
before do
343+
expect(view).to receive(:special_selector).and_call_original
344+
end
345+
326346
it 'creates a special query selector' do
327347
expect(query_spec[:selector][:$orderby]).to eq(options[:sort])
328348
end
@@ -358,6 +378,10 @@
358378
{ :comment => 'query1' }
359379
end
360380

381+
before do
382+
expect(view).to receive(:special_selector).and_call_original
383+
end
384+
361385
it 'creates a special query selector' do
362386
expect(query_spec[:selector][:$comment]).to eq(options[:comment])
363387
end
@@ -392,6 +416,10 @@
392416
}
393417
end
394418

419+
before do
420+
expect(view).to receive(:special_selector).and_call_original
421+
end
422+
395423
it 'creates a special query selector' do
396424
expect(query_spec[:selector][:$orderby]).to eq(options[:modifiers][:$orderby])
397425
end

spec/support/crud/read.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def aggregate(collection)
105105
end
106106

107107
def distinct(collection)
108-
collection.distinct(field_name, filter)
108+
collection.distinct(field_name, filter, options)
109109
end
110110

111111
def find(collection)

spec/support/crud/write.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def find_one_and_delete(collection)
158158
end
159159

160160
def find_one_and_replace(collection)
161-
collection.find_one_and_replace(filter, replacement,options)
161+
collection.find_one_and_replace(filter, replacement, options)
162162
end
163163

164164
def find_one_and_update(collection)

0 commit comments

Comments
 (0)