1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-09-19 17:10:34 +00:00
puppet-rsnapshot/lib/puppet/parser/functions/assert_empty_hash.rb
2015-12-22 00:20:58 +01:00

21 lines
615 B
Ruby

module Puppet::Parser::Functions
newfunction(:assert_empty_hash, :type => :rvalue, :doc => <<-EOS
This function checks an input struct for undefined hashes in key => hash and assigns {}. This is only a helper function to make a hash.each work if one of the values is undefined
EOS
)do |args|
fail "Must receive one argument." if args.empty?
return args if args.is_a?(String)
return args if args.is_a?(Integer)
args.each do |arg|
h = Hash.new
arg.each_pair do |host, hash|
unless hash.is_a? Hash
hash = {}
end
h[host] = hash
end
return h
end
end
end