Skip to content

Commit fd7676a

Browse files
committed
appease Lint/IneffectiveAccessModifier
1 parent d872d52 commit fd7676a

File tree

4 files changed

+76
-74
lines changed

4 files changed

+76
-74
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ Lint/IncompatibleIoSelectWithFiberScheduler:
4242
- 'lib/mongo/socket/ssl.rb'
4343
- 'lib/mongo/socket/tcp.rb'
4444

45-
# Offense count: 7
46-
Lint/IneffectiveAccessModifier:
47-
Exclude:
48-
- 'lib/mongo/operation/shared/polymorphic_result.rb'
49-
- 'lib/mongo/protocol/message.rb'
50-
- 'lib/mongo/uri/options_mapper.rb'
5145

5246

5347
# Offense count: 31

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

lib/mongo/uri/options_mapper.rb

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,28 @@ def ruby_to_string(opts)
185185
rv
186186
end
187187

188+
# Hash for storing map of URI option parameters to conversion strategies
189+
# @api private
190+
URI_OPTION_MAP = {}
191+
192+
# @return [ Hash<String, String> ] Map from lowercased to canonical URI
193+
# option names.
194+
# @api private
195+
URI_OPTION_CANONICAL_NAMES = {}
196+
197+
# Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP.
198+
#
199+
# @param [ String ] uri_key The MongoDB URI option to register.
200+
# @param [ Symbol ] name The name of the option in the driver.
201+
# @param [ Hash ] extra Extra options.
202+
# * :group [ Symbol ] Nested hash where option will go.
203+
# * :type [ Symbol ] Name of function to transform value.
204+
# @api private
205+
def self.uri_option(uri_key, name, **extra)
206+
URI_OPTION_MAP[uri_key.downcase] = { name: name }.update(extra)
207+
URI_OPTION_CANONICAL_NAMES[uri_key.downcase] = uri_key
208+
end
209+
188210
private
189211

190212
# Applies URI value transformation by either using the default cast
@@ -224,25 +246,6 @@ def merge_uri_option(target, value, name)
224246
end
225247
end
226248

227-
# Hash for storing map of URI option parameters to conversion strategies
228-
URI_OPTION_MAP = {}
229-
230-
# @return [ Hash<String, String> ] Map from lowercased to canonical URI
231-
# option names.
232-
URI_OPTION_CANONICAL_NAMES = {}
233-
234-
# Simple internal dsl to register a MongoDB URI option in the URI_OPTION_MAP.
235-
#
236-
# @param [ String ] uri_key The MongoDB URI option to register.
237-
# @param [ Symbol ] name The name of the option in the driver.
238-
# @param [ Hash ] extra Extra options.
239-
# * :group [ Symbol ] Nested hash where option will go.
240-
# * :type [ Symbol ] Name of function to transform value.
241-
def self.uri_option(uri_key, name, **extra)
242-
URI_OPTION_MAP[uri_key.downcase] = { name: name }.update(extra)
243-
URI_OPTION_CANONICAL_NAMES[uri_key.downcase] = uri_key
244-
end
245-
246249
# Replica Set Options
247250
uri_option 'replicaSet', :replica_set
248251

0 commit comments

Comments
 (0)