Skip to content

(FM-7547) move function definitions out of Puppet function #1139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 2 additions & 20 deletions lib/puppet/parser/functions/mysql_deepmerge.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require_relative '../../../puppet_x/puppetlabs/mysql_utilities'
module Puppet::Parser::Functions
newfunction(:mysql_deepmerge, type: :rvalue, doc: <<-'ENDHEREDOC') do |args|
@summary Recursively merges two or more hashes together and returns the resulting hash.
Expand Down Expand Up @@ -32,27 +33,8 @@ module Puppet::Parser::Functions
# Now we have to traverse our hash assigning our non-hash values
# to the matching keys in our result while following our hash values
# and repeating the process.
overlay(result, arg)
PuppetX::Puppetlabs::MysqlUtilities.overlay(result, arg)
end
return(result)
end
end

def normalized?(hash, key)
return true if hash.key?(key)
return false unless key =~ %r{-|_}
other_key = key.include?('-') ? key.tr('-', '_') : key.tr('_', '-')
return false unless hash.key?(other_key)
hash[key] = hash.delete(other_key)
true
end

def overlay(hash1, hash2)
hash2.each do |key, value|
if normalized?(hash1, key) && value.is_a?(Hash) && hash1[key].is_a?(Hash)
overlay(hash1[key], value)
else
hash1[key] = value
end
end
end
25 changes: 25 additions & 0 deletions lib/puppet_x/puppetlabs/mysql_utilities.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module PuppetX
module Puppetlabs
class MysqlUtilities
def self.normalized?(hash, key)
return true if hash.key?(key)
return false unless key =~ %r{-|_}
other_key = key.include?('-') ? key.tr('-', '_') : key.tr('_', '-')
return false unless hash.key?(other_key)
hash[key] = hash.delete(other_key)
true
end

def self.overlay(hash1, hash2)
hash2.each do |key, value|
if self.normalized?(hash1, key) && value.is_a?(Hash) && hash1[key].is_a?(Hash)
self.overlay(hash1[key], value)
else
hash1[key] = value
end
end
end
end
end
end