1
0
mirror of https://github.com/krislamo/puppet-rsnapshot synced 2024-11-14 09:00:35 +00:00
puppet-rsnapshot/lib/puppet/parser/functions/assert_empty_hash.rb

21 lines
615 B
Ruby
Raw Normal View History

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?
2015-12-21 23:20:58 +00:00
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