Skip to content

Commit e113971

Browse files
committed
feedback from copilot
1 parent 74cfcb5 commit e113971

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

lib/mongo.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434

3535
require 'bson'
3636

37-
require 'mongo/deprecations'
3837
require 'mongo/id'
3938
require 'mongo/bson'
4039
require 'mongo/semaphore'
@@ -43,6 +42,7 @@
4342
require 'mongo/csot_timeout_holder'
4443
require 'mongo/options'
4544
require 'mongo/loggable'
45+
require 'mongo/deprecations'
4646
require 'mongo/cluster_time'
4747
require 'mongo/topology_version'
4848
require 'mongo/monitoring'

lib/mongo/deprecations.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ module Deprecations
2525

2626
# Issue a warning about a deprecated feature. The warning is written to the
2727
# logger, and will not be written more than once per feature.
28+
#
29+
# @param [ String | Symbol ] feature The deprecated feature.
30+
# @param [ String ] message The deprecation message.
2831
def warn(feature, message)
2932
MUTEX.synchronize do
3033
return if _warned?(feature)
@@ -37,6 +40,7 @@ def warn(feature, message)
3740
# Check if a warning for a given deprecated feature has already been issued.
3841
#
3942
# @param [ String | Symbol ] feature The deprecated feature.
43+
# @param [ true | false ] prefix Whether to check for prefix matches.
4044
#
4145
# @return [ true | false ] If a warning has already been issued.
4246
def warned?(feature, prefix: false)
@@ -48,21 +52,34 @@ def warned?(feature, prefix: false)
4852
# @param [ String | Symbol ] feature The deprecated feature.
4953
def warned!(feature)
5054
MUTEX.synchronize { _warned!(feature) }
55+
nil
5156
end
5257

5358
# Clears all memory of previously warned features.
5459
def clear!
5560
MUTEX.synchronize { warned_features reset: true }
56-
true
61+
nil
5762
end
5863

5964
private
6065

66+
# Set of features that have already been warned about.
67+
#
68+
# @param [ true | false ] reset Whether to reset the warned features.
69+
#
70+
# @return [ Set<String> ] The set of warned features.
6171
def warned_features(reset: false)
6272
@warned_features = nil if reset
6373
@warned_features ||= Set.new
6474
end
6575

76+
# Check if a warning for a given deprecated feature has already been issued.
77+
# This version is not thread-safe.
78+
#
79+
# @param [ String | Symbol ] feature The deprecated feature.
80+
# @param [ true | false ] prefix Whether to check for prefix matches.
81+
#
82+
# @return [ true | false ] If a warning has already been issued.
6683
def _warned?(feature, prefix: false)
6784
if prefix
6885
warned_features.any? { |f| feature.to_s.start_with?(f) }
@@ -71,6 +88,10 @@ def _warned?(feature, prefix: false)
7188
end
7289
end
7390

91+
# Mark that a warning for a given deprecated feature has been issued.
92+
# This version is not thread-safe.
93+
#
94+
# @param [ String | Symbol ] feature The deprecated feature.
7495
def _warned!(feature)
7596
warned_features.add(feature.to_s)
7697
end

lib/mongo/server/description/features.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class Features
8585
DRIVER_TOO_OLD = "Server at (%s) requires wire version (%s), but this version of the Ruby driver " +
8686
"only supports up to (%s)."
8787

88+
# An empty range constant, for use in DEPRECATED_WIRE_VERSIONS.
89+
EMPTY_RANGE = (0...0).freeze
90+
8891
# The wire protocol versions that this version of the driver supports.
8992
#
9093
# @since 2.0.0
@@ -100,9 +103,16 @@ class Features
100103
# be set to a range where the min and max are the same value.
101104
#
102105
# If there are no currently-deprecated wire versions, this should be
103-
# set to an empty array.
106+
# set to an empty range (e.g. the EMPTY_RANGE constant).
104107
DEPRECATED_WIRE_VERSIONS = 6..6
105108

109+
# make sure the deprecated versions are valid
110+
if DEPRECATED_WIRE_VERSIONS.min
111+
if DRIVER_WIRE_VERSIONS.min > DEPRECATED_WIRE_VERSIONS.max
112+
raise ArgumentError, 'DEPRECATED_WIRE_VERSIONS must be empty, or be within DRIVER_WIRE_VERSIONS'
113+
end
114+
end
115+
106116
# Create the methods for each mapping to tell if they are supported.
107117
#
108118
# @since 2.0.0

0 commit comments

Comments
 (0)