File tree 2 files changed +27
-20
lines changed
2 files changed +27
-20
lines changed Original file line number Diff line number Diff line change
1
+ require_relative '../../../puppet_x/puppetlabs/mysql_utilities'
1
2
module Puppet ::Parser ::Functions
2
3
newfunction ( :mysql_deepmerge , type : :rvalue , doc : <<-'ENDHEREDOC' ) do |args |
3
4
@summary Recursively merges two or more hashes together and returns the resulting hash.
@@ -32,27 +33,8 @@ module Puppet::Parser::Functions
32
33
# Now we have to traverse our hash assigning our non-hash values
33
34
# to the matching keys in our result while following our hash values
34
35
# and repeating the process.
35
- overlay ( result , arg )
36
+ PuppetX :: Puppetlabs :: MysqlUtilities . overlay ( result , arg )
36
37
end
37
38
return ( result )
38
39
end
39
40
end
40
-
41
- def normalized? ( hash , key )
42
- return true if hash . key? ( key )
43
- return false unless key =~ %r{-|_}
44
- other_key = key . include? ( '-' ) ? key . tr ( '-' , '_' ) : key . tr ( '_' , '-' )
45
- return false unless hash . key? ( other_key )
46
- hash [ key ] = hash . delete ( other_key )
47
- true
48
- end
49
-
50
- def overlay ( hash1 , hash2 )
51
- hash2 . each do |key , value |
52
- if normalized? ( hash1 , key ) && value . is_a? ( Hash ) && hash1 [ key ] . is_a? ( Hash )
53
- overlay ( hash1 [ key ] , value )
54
- else
55
- hash1 [ key ] = value
56
- end
57
- end
58
- end
Original file line number Diff line number Diff line change
1
+ module PuppetX
2
+ module Puppetlabs
3
+ class MysqlUtilities
4
+ def self . normalized? ( hash , key )
5
+ return true if hash . key? ( key )
6
+ return false unless key =~ %r{-|_}
7
+ other_key = key . include? ( '-' ) ? key . tr ( '-' , '_' ) : key . tr ( '_' , '-' )
8
+ return false unless hash . key? ( other_key )
9
+ hash [ key ] = hash . delete ( other_key )
10
+ true
11
+ end
12
+
13
+ def self . overlay ( hash1 , hash2 )
14
+ hash2 . each do |key , value |
15
+ if self . normalized? ( hash1 , key ) && value . is_a? ( Hash ) && hash1 [ key ] . is_a? ( Hash )
16
+ self . overlay ( hash1 [ key ] , value )
17
+ else
18
+ hash1 [ key ] = value
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+
You can’t perform that action at this time.
0 commit comments