X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=modules%2Fpuppetmaster%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgetfromhash.rb;h=69fdeb54e5372861d45044a7c7b75ef2ea1f9016;hb=8d4c37d69d3ba8a6c7b722aaa6bc11dc5e7b7d3e;hp=e948929d6a010add34e71cd9f129160848a2d173;hpb=a07d3c87c702f358bd36d52f423c1f437307b015;p=mirror%2Fdsa-puppet.git diff --git a/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb b/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb index e948929d6..69fdeb54e 100644 --- a/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb +++ b/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb @@ -1,16 +1,21 @@ module Puppet::Parser::Functions newfunction(:getfromhash, :type => :rvalue) do |args| - h = args.shift - key = args.shift + x = args.shift + keys = args + keys_done = [] - raise Puppet::ParseError, "argument is not a hash" unless h.kind_of?(Hash) - if h.has_key?(key) - ans = h[key] - else - ans = false + # allows getting of hash[key] or even hash[key1][key2] etc. + keys.each do |key| + raise Puppet::ParseError, "argument[#{keys_done.join('][')}] is not a hash." unless x.kind_of?(Hash) + unless x.has_key?(key) + x = false + break + end + x = x[key] + keys_done << key end - return ans + return x end end # vim:set et: