Skip to content

Commit 0a33b88

Browse files
committed
RUBY-1021 Take out unnecessary self refs
1 parent 42b6283 commit 0a33b88

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

lib/mongo/options/redacted.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ class Redacted < BSON::Document
2525
#
2626
# @since 2.1.0
2727
SENSITIVE_OPTIONS = [ :password,
28-
:pwd ]
28+
:pwd ].freeze
2929

3030
# The replacement string used in place of the value for sensitive keys.
3131
#
3232
# @since 2.1.0
33-
STRING_REPLACEMENT = '<REDACTED>'
33+
STRING_REPLACEMENT = '<REDACTED>'.freeze
3434

3535
# Get a string representation of the options.
3636
#
@@ -93,12 +93,12 @@ def reject(&block)
9393
def reject!
9494
if block_given?
9595
n_keys = keys.size
96-
self.keys.each do |key|
97-
self.delete(key) if yield(key, self[key])
96+
keys.each do |key|
97+
delete(key) if yield(key, self[key])
9898
end
9999
n_keys == keys.size ? nil : self
100100
else
101-
self.to_enum
101+
to_enum
102102
end
103103
end
104104

@@ -130,12 +130,12 @@ def select(&block)
130130
def select!
131131
if block_given?
132132
n_keys = keys.size
133-
self.keys.each do |key|
134-
self.delete(key) unless yield(key, self[key])
133+
keys.each do |key|
134+
delete(key) unless yield(key, self[key])
135135
end
136136
n_keys == keys.size ? nil : self
137137
else
138-
self.to_enum
138+
to_enum
139139
end
140140
end
141141

lib/mongo/server_selector.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module ServerSelector
4141
# Primary read preference.
4242
#
4343
# @since 2.1.0
44-
PRIMARY = Options::Redacted.new(mode: :primary)
44+
PRIMARY = Options::Redacted.new(mode: :primary).freeze
4545

4646
# Hash lookup for the selector classes based off the symbols
4747
# provided in configuration.

spec/mongo/options/redacted_spec.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,12 @@
2525

2626
context 'when the hash does not contain a sensitive key' do
2727

28-
it 'prints all the values' do
28+
let(:original_opts) do
29+
{ user: 'emily' }
30+
end
2931

32+
it 'prints all the values' do
33+
expect(options.to_s).to match(original_opts[:user])
3034
end
3135
end
3236
end

0 commit comments

Comments
 (0)