Skip to content

Commit 8cd13e9

Browse files
committed
Merge branch 'master' into cleanup-TODO
2 parents fe0c6ec + 55b5b7f commit 8cd13e9

40 files changed

+606
-267
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,12 @@
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 7
10-
# This cop supports safe autocorrection (--autocorrect).
11-
Layout/MultilineBlockLayout:
12-
Exclude:
13-
- 'lib/mongo/crypt/handle.rb'
14-
15-
# Offense count: 2
16-
# This cop supports safe autocorrection (--autocorrect).
17-
Layout/RescueEnsureAlignment:
18-
Exclude:
19-
- 'spec/mongo/collection/view/change_stream_spec.rb'
20-
- 'spec/mongo/collection/view/readable_spec.rb'
21-
22-
# Offense count: 8
23-
# This cop supports unsafe autocorrection (--autocorrect-all).
24-
# Configuration parameters: RequireParenthesesForMethodChains.
25-
Lint/AmbiguousRange:
26-
Exclude:
27-
- 'spec/integration/sdam_events_spec.rb'
28-
- 'spec/mongo/server/description/features_spec.rb'
29-
- 'spec/runners/unified.rb'
30-
319
# Offense count: 190
3210
# This cop supports unsafe autocorrection (--autocorrect-all).
3311
# Configuration parameters: AllowSafeAssignment.
3412
Lint/AssignmentInCondition:
3513
Enabled: false
3614

37-
# Offense count: 10
38-
# Configuration parameters: AllowedMethods.
39-
# AllowedMethods: enums
40-
Lint/ConstantDefinitionInBlock:
41-
Exclude:
42-
- 'spec/integration/heartbeat_events_spec.rb'
43-
- 'spec/mongo/id_spec.rb'
44-
- 'spec/mongo/operation/result_spec.rb'
45-
- 'spec/mongo/server/connection_spec.rb'
46-
- 'spec/spec_tests/sdam_spec.rb'
47-
4815
# Offense count: 16
4916
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches, IgnoreDuplicateElseBranch.
5017
Lint/DuplicateBranch:
@@ -63,56 +30,13 @@ Lint/DuplicateBranch:
6330
- 'spec/runners/sdam.rb'
6431
- 'spec/support/client_registry.rb'
6532

66-
# Offense count: 3
67-
Lint/DuplicateMethods:
68-
Exclude:
69-
- 'spec/runners/auth.rb'
70-
- 'spec/runners/cmap.rb'
71-
- 'spec/support/spec_config.rb'
72-
73-
# Offense count: 8
74-
# Configuration parameters: AllowComments, AllowEmptyLambdas.
75-
Lint/EmptyBlock:
76-
Exclude:
77-
- 'spec/integration/cursor_memory_leak_spec.rb'
78-
- 'spec/mongo/auth/user_spec.rb'
79-
- 'spec/mongo/cursor_spec.rb'
80-
- 'spec/mongo/server/description_spec.rb'
81-
- 'spec/mongo/server/round_trip_time_calculator_spec.rb'
82-
- 'spec/mongo/uri/srv_protocol_spec.rb'
83-
84-
# Offense count: 3
85-
# This cop supports safe autocorrection (--autocorrect).
86-
# Configuration parameters: AllowComments.
87-
Lint/EmptyConditionalBody:
88-
Exclude:
89-
- 'spec/runners/transactions.rb'
90-
- 'spec/spec_tests/uri_options_spec.rb'
91-
9233
# Offense count: 4
9334
# This cop supports unsafe autocorrection (--autocorrect-all).
9435
Lint/IncompatibleIoSelectWithFiberScheduler:
9536
Exclude:
9637
- 'lib/mongo/socket/ssl.rb'
9738
- 'lib/mongo/socket/tcp.rb'
9839

99-
# Offense count: 7
100-
Lint/IneffectiveAccessModifier:
101-
Exclude:
102-
- 'lib/mongo/operation/shared/polymorphic_result.rb'
103-
- 'lib/mongo/protocol/message.rb'
104-
- 'lib/mongo/uri/options_mapper.rb'
105-
106-
# Offense count: 4
107-
# This cop supports unsafe autocorrection (--autocorrect-all).
108-
# Configuration parameters: EnforcedStyle.
109-
# SupportedStyles: standard_error, runtime_error
110-
Lint/InheritException:
111-
Exclude:
112-
- 'lib/mongo/error/raise_original_error.rb'
113-
- 'spec/mongo/server/connection_spec.rb'
114-
- 'spec/mongo/socket_spec.rb'
115-
11640
# Offense count: 31
11741
# Configuration parameters: AllowedParentClasses.
11842
Lint/MissingSuper:
@@ -128,12 +52,6 @@ Lint/NextWithoutAccumulator:
12852
Exclude:
12953
- 'lib/mongo/operation/shared/result/aggregatable.rb'
13054

131-
# Offense count: 2
132-
Lint/NoReturnInBeginEndBlocks:
133-
Exclude:
134-
- 'lib/mongo/socket/ocsp_verifier.rb'
135-
- 'spec/runners/change_streams/test.rb'
136-
13755
# Offense count: 1
13856
Lint/NonLocalExitFromIterator:
13957
Exclude:

lib/mongo/crypt/handle.rb

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ def do_rsaes_pkcs_signature(key_binary_p, input_binary_p,
288288
# Every crypto binding ignores its first argument, which is an option
289289
# mongocrypt_ctx_t object and is not required to use crypto hooks.
290290
def set_crypto_hooks
291-
@aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
292-
output_binary_p, response_length_p, status_p|
291+
@aes_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
293292
do_aes(
294293
key_binary_p,
295294
iv_binary_p,
@@ -300,8 +299,7 @@ def set_crypto_hooks
300299
)
301300
end
302301

303-
@aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
304-
output_binary_p, response_length_p, status_p|
302+
@aes_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
305303
do_aes(
306304
key_binary_p,
307305
iv_binary_p,
@@ -319,13 +317,11 @@ def set_crypto_hooks
319317
end
320318
end
321319

322-
@hmac_sha_512 = proc do |_, key_binary_p, input_binary_p,
323-
output_binary_p, status_p|
320+
@hmac_sha_512 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
324321
do_hmac_sha('SHA512', key_binary_p, input_binary_p, output_binary_p, status_p)
325322
end
326323

327-
@hmac_sha_256 = proc do |_, key_binary_p, input_binary_p,
328-
output_binary_p, status_p|
324+
@hmac_sha_256 = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
329325
do_hmac_sha('SHA256', key_binary_p, input_binary_p, output_binary_p, status_p)
330326
end
331327

@@ -347,8 +343,7 @@ def set_crypto_hooks
347343
@hmac_hash
348344
)
349345

350-
@aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
351-
output_binary_p, response_length_p, status_p|
346+
@aes_ctr_encrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
352347
do_aes(
353348
key_binary_p,
354349
iv_binary_p,
@@ -360,8 +355,7 @@ def set_crypto_hooks
360355
)
361356
end
362357

363-
@aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p,
364-
output_binary_p, response_length_p, status_p|
358+
@aes_ctr_decrypt = proc do |_, key_binary_p, iv_binary_p, input_binary_p, output_binary_p, response_length_p, status_p|
365359
do_aes(
366360
key_binary_p,
367361
iv_binary_p,
@@ -380,8 +374,7 @@ def set_crypto_hooks
380374
@aes_ctr_decrypt
381375
)
382376

383-
@rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p,
384-
output_binary_p, status_p|
377+
@rsaes_pkcs_signature_cb = proc do |_, key_binary_p, input_binary_p, output_binary_p, status_p|
385378
do_rsaes_pkcs_signature(key_binary_p, input_binary_p, output_binary_p, status_p)
386379
end
387380

lib/mongo/error/raise_original_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Error
2424
# @note This class must not derive from Error.
2525
#
2626
# @api private
27-
class RaiseOriginalError < Exception
27+
class RaiseOriginalError < Exception # rubocop:disable Lint/InheritException
2828
end
2929
end
3030
end

lib/mongo/operation/shared/polymorphic_result.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ module Operation
2626
module PolymorphicResult
2727
include PolymorphicLookup
2828

29-
private
30-
3129
def self.included(base)
3230
base.extend ClassMethods
3331
end
3432

33+
private
34+
3535
module ClassMethods
3636
attr_accessor :result_class
3737
end

lib/mongo/protocol/message.rb

Lines changed: 52 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -320,64 +320,19 @@ def number_returned
320320
0
321321
end
322322

323-
private
324-
325-
# A method for getting the fields for a message class
326-
#
327-
# @return [Integer] the fields for the message class
328-
def fields
329-
self.class.fields
330-
end
331-
332323
# A class method for getting the fields for a message class
333324
#
334325
# @return [Integer] the fields for the message class
326+
# @api private
335327
def self.fields
336328
@fields ||= []
337329
end
338330

339-
# Serializes message fields into a buffer
340-
#
341-
# @param buffer [String] buffer to receive the field
342-
# @return [String] buffer with serialized field
343-
def serialize_fields(buffer, max_bson_size = nil)
344-
fields.each do |field|
345-
value = instance_variable_get(field[:name])
346-
if field[:multi]
347-
value.each do |item|
348-
if field[:type].respond_to?(:size_limited?)
349-
field[:type].serialize(buffer, item, max_bson_size)
350-
else
351-
field[:type].serialize(buffer, item)
352-
end
353-
end
354-
elsif field[:type].respond_to?(:size_limited?)
355-
field[:type].serialize(buffer, value, max_bson_size)
356-
else
357-
field[:type].serialize(buffer, value)
358-
end
359-
end
360-
end
361-
362-
# Serializes the header of the message consisting of 4 32bit integers
363-
#
364-
# The integers represent a message length placeholder (calculation of
365-
# the actual length is deferred) the request id, the response to id,
366-
# and the op code for the message
367-
#
368-
# Currently uses hardcoded 0 for request id and response to as their
369-
# values are irrelevent to the server
370-
#
371-
# @param buffer [String] Buffer to receive the header
372-
# @return [String] Serialized header
373-
def serialize_header(buffer)
374-
Header.serialize(buffer, [ 0, request_id, 0, op_code ])
375-
end
376-
377331
# Deserializes the header of the message
378332
#
379333
# @param io [IO] Stream containing the header.
380334
# @return [Array<Fixnum>] Deserialized header.
335+
# @api private
381336
def self.deserialize_header(io)
382337
Header.deserialize(io)
383338
end
@@ -397,6 +352,7 @@ def self.deserialize_header(io)
397352
# fields that use the number.
398353
#
399354
# @return [NilClass]
355+
# @api private
400356
def self.field(name, type, multi = false)
401357
fields << {
402358
name: :"@#{name}",
@@ -422,6 +378,7 @@ def self.field(name, type, multi = false)
422378
# each of the elements in this array using BSON types wherever possible.
423379
#
424380
# @return [Message] Message with deserialized array.
381+
# @api private
425382
def self.deserialize_array(message, io, field, options = {})
426383
elements = []
427384
count = message.instance_variable_get(field[:multi])
@@ -440,12 +397,60 @@ def self.deserialize_array(message, io, field, options = {})
440397
# this field using BSON types wherever possible.
441398
#
442399
# @return [Message] Message with deserialized field.
400+
# @api private
443401
def self.deserialize_field(message, io, field, options = {})
444402
message.instance_variable_set(
445403
field[:name],
446404
field[:type].deserialize(io, options)
447405
)
448406
end
407+
408+
private
409+
410+
# A method for getting the fields for a message class
411+
#
412+
# @return [Integer] the fields for the message class
413+
def fields
414+
self.class.fields
415+
end
416+
417+
# Serializes message fields into a buffer
418+
#
419+
# @param buffer [String] buffer to receive the field
420+
# @return [String] buffer with serialized field
421+
def serialize_fields(buffer, max_bson_size = nil)
422+
fields.each do |field|
423+
value = instance_variable_get(field[:name])
424+
if field[:multi]
425+
value.each do |item|
426+
if field[:type].respond_to?(:size_limited?)
427+
field[:type].serialize(buffer, item, max_bson_size)
428+
else
429+
field[:type].serialize(buffer, item)
430+
end
431+
end
432+
elsif field[:type].respond_to?(:size_limited?)
433+
field[:type].serialize(buffer, value, max_bson_size)
434+
else
435+
field[:type].serialize(buffer, value)
436+
end
437+
end
438+
end
439+
440+
# Serializes the header of the message consisting of 4 32bit integers
441+
#
442+
# The integers represent a message length placeholder (calculation of
443+
# the actual length is deferred) the request id, the response to id,
444+
# and the op code for the message
445+
#
446+
# Currently uses hardcoded 0 for request id and response to as their
447+
# values are irrelevent to the server
448+
#
449+
# @param buffer [String] Buffer to receive the header
450+
# @return [String] Serialized header
451+
def serialize_header(buffer)
452+
Header.serialize(buffer, [ 0, request_id, 0, op_code ])
453+
end
449454
end
450455
end
451456
end

0 commit comments

Comments
 (0)