Skip to content

Commit e8b5f84

Browse files
committed
(FM-7547) move function definitions out of Puppet function
In Puppet 5.5.7, legacy functions that had ruby functions defined in the file no longer work. This puts it into a library class.
1 parent 3777521 commit e8b5f84

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

lib/puppet/parser/functions/mysql_deepmerge.rb

+2-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require_relative '../../../puppet_x/puppetlabs/mysql_utilities'
12
module Puppet::Parser::Functions
23
newfunction(:mysql_deepmerge, type: :rvalue, doc: <<-'ENDHEREDOC') do |args|
34
@summary Recursively merges two or more hashes together and returns the resulting hash.
@@ -32,27 +33,8 @@ module Puppet::Parser::Functions
3233
# Now we have to traverse our hash assigning our non-hash values
3334
# to the matching keys in our result while following our hash values
3435
# and repeating the process.
35-
overlay(result, arg)
36+
PuppetX::Puppetlabs::MysqlUtilities.overlay(result, arg)
3637
end
3738
return(result)
3839
end
3940
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
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+

0 commit comments

Comments
 (0)