Skip to content

Commit a54ba60

Browse files
committed
(MODULES-8886) Rename deepmerge to normalise_and_deepmerge
1 parent 8f1c4b9 commit a54ba60

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

lib/puppet/functions/mysql/deepmerge.rb lib/puppet/functions/mysql/normalise_and_deepmerge.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,29 @@
1-
# @summary Recursively merges two or more hashes together and returns the resulting hash.
1+
# @summary Recursively merges two or more hashes together, normalises keys with differing use of dashesh and underscores,
2+
# then returns the resulting hash.
23
#
34
# @example
45
# $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }
56
# $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } }
6-
# $merged_hash = mysql::deepmerge($hash1, $hash2)
7+
# $merged_hash = mysql::normalise_and_deepmerge($hash1, $hash2)
78
# # The resulting hash is equivalent to:
89
# # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } }
910
#
1011
# - When there is a duplicate key that is a hash, they are recursively merged.
1112
# - When there is a duplicate key that is not a hash, the key in the rightmost hash will "win."
1213
# - When there are conficting uses of dashes and underscores in two keys (which mysql would otherwise equate), the rightmost style will win.
1314
#
14-
Puppet::Functions.create_function(:'mysql::deepmerge') do
15-
def deepmerge(*args)
15+
Puppet::Functions.create_function(:'mysql::normalise_and_deepmerge') do
16+
def normalise_and_deepmerge(*args)
1617
if args.length < 2
17-
raise Puppet::ParseError, _('mysql::deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length }
18+
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge(): wrong number of arguments (%{args_length}; must be at least 2)') % { args_length: args.length }
1819
end
1920

2021
result = {}
2122
args.each do |arg|
2223
next if arg.is_a?(String) && arg.empty? # empty string is synonym for puppet's undef
2324
# If the argument was not a hash, skip it.
2425
unless arg.is_a?(Hash)
25-
raise Puppet::ParseError, _('mysql::deepmerge: unexpected argument type %{arg_class}, only expects hash arguments.') % { args_class: args.class }
26+
raise Puppet::ParseError, _('mysql::normalise_and_deepmerge: unexpected argument type %{arg_class}, only expects hash arguments.') % { args_class: args.class }
2627
end
2728

2829
# We need to make a copy of the hash since it is frozen by puppet

manifests/backup/mysqlbackup.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
'password' => $backuppassword,
9494
}
9595
}
96-
$options = mysql::deepmerge($default_options, $mysql::server::override_options)
96+
$options = mysql::normalise_and_deepmerge($default_options, $mysql::server::override_options)
9797

9898
file { 'mysqlbackup-config-file':
9999
path => '/etc/mysql/conf.d/meb.cnf',

manifests/server.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
}
117117

118118
# Create a merged together set of options. Rightmost hashes win over left.
119-
$options = mysql::deepmerge($mysql::params::default_options, $override_options)
119+
$options = mysql::normalise_and_deepmerge($mysql::params::default_options, $override_options)
120120

121121
Class['mysql::server::root_password'] -> Mysql::Db <| |>
122122

spec/functions/mysql_deepmerge_spec.rb spec/functions/mysql_normalise_and_deepmerge_spec.rb

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
require 'spec_helper'
44

5-
describe 'mysql::deepmerge' do
5+
describe 'mysql::normalise_and_deepmerge' do
66
it 'exists' do
77
is_expected.not_to eq(nil)
88
end
@@ -22,14 +22,14 @@
2222
# rubocop:disable RSpec/NamedSubject
2323
index_values = ['one', 'two', 'three']
2424
expected_values_one = ['1', '2', '2']
25-
it 'is able to mysql_deepmerge two hashes' do
25+
it 'merge two hashes' do
2626
new_hash = subject.execute({ 'one' => '1', 'two' => '1' }, 'two' => '2', 'three' => '2')
2727
index_values.each_with_index do |index, expected|
2828
expect(new_hash[index]).to eq(expected_values_one[expected])
2929
end
3030
end
3131

32-
it 'mysql_deepmerges multiple hashes' do
32+
it 'merges multiple hashes' do
3333
hash = subject.execute({ 'one' => 1 }, { 'one' => '2' }, 'one' => '3')
3434
expect(hash['one']).to eq('3')
3535
end
@@ -39,7 +39,7 @@
3939
end
4040

4141
expected_values_two = [1, 2, 'four' => 4]
42-
it 'mysql_deepmerges subhashes' do
42+
it 'merges subhashes' do
4343
hash = subject.execute({ 'one' => 1 }, 'two' => 2, 'three' => { 'four' => 4 })
4444
index_values.each_with_index do |index, expected|
4545
expect(hash[index]).to eq(expected_values_two[expected])

0 commit comments

Comments
 (0)