Skip to content

Commit afbe202

Browse files
committed
RUBY-1021 Use helper method to build string
1 parent 1338f16 commit afbe202

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

lib/mongo/options/redacted.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,7 @@ class Redacted < BSON::Document
3838
#
3939
# @since 2.1.0
4040
def inspect
41-
'{' + reduce([]) do |list, (k, v)|
42-
list << "#{k.inspect}=>#{redact(k, v, __method__)}"
43-
end.join(', ') + '}'
41+
redacted_string(__method__)
4442
end
4543

4644
# Get a string representation of the options.
@@ -49,9 +47,7 @@ def inspect
4947
#
5048
# @since 2.1.0
5149
def to_s
52-
'{' + reduce([]) do |list, (k, v)|
53-
list << "#{k.to_s}=>#{redact(k, v, __method__)}"
54-
end.join(', ') + '}'
50+
redacted_string(__method__)
5551
end
5652

5753
# Whether these options contain a given key.
@@ -70,6 +66,12 @@ def has_key?(key)
7066

7167
private
7268

69+
def redacted_string(method)
70+
'{' + reduce([]) do |list, (k, v)|
71+
list << "#{k.send(method)}=>#{redact(k, v, method)}"
72+
end.join(', ') + '}'
73+
end
74+
7375
def redact(k, v, method)
7476
return STRING_REPLACEMENT if SENSITIVE_OPTIONS.include?(k.to_sym)
7577
v.send(method)

0 commit comments

Comments
 (0)