Skip to content

Commit 3e4d3c3

Browse files
committed
Use a more expressive method of rewriting values
This achieves almost the same, except that this version doesn't change the original value. If that's really desired, `transform_values!` can be used. The tests are modified to stop counting on the value being replaced by explicitly writing out the expected value. It also switches to a string check and `match?` because in modern Ruby `=~` is no longer defined for arrays. This is needed for Puppet 8 compatibility.
1 parent c4785ff commit 3e4d3c3

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/puppet/type/rabbitmq_parameter.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ def validate_value(value)
106106
def munge_value(value)
107107
return value if value(:autoconvert) == :false
108108

109-
value.each do |k, v|
110-
value[k] = v.to_i if v =~ %r{\A[-+]?[0-9]+\z}
109+
value.transform_values do |v|
110+
if v.is_a?(String) && v.match?(%r{\A[-+]?[0-9]+\z})
111+
v.to_i
112+
else
113+
v
114+
end
111115
end
112-
value
113116
end
114117
end

spec/unit/puppet/type/rabbitmq_parameter_spec.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,8 @@
4444
end
4545

4646
it 'accepts a valid hash for value' do
47-
value = { 'message-ttl' => '1800000' }
48-
parameter[:value] = value
49-
expect(parameter[:value]).to eq(value)
47+
parameter[:value] = { 'message-ttl' => '1800000' }
48+
expect(parameter[:value]).to eq({ 'message-ttl' => 1_800_000 })
5049
end
5150

5251
it 'does not accept an empty string for definition' do

0 commit comments

Comments
 (0)