From 286882d21d15ddbc07b67fa08e4c36ad6e06b898 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Wed, 2 Mar 2011 18:54:37 +0100 Subject: [PATCH] Restore extractnodeinfo support for extracing 2nd and higher level hash keys, as in foo[bar][baz] --- .../puppet/parser/functions/getfromhash.rb | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb b/modules/puppetmaster/lib/puppet/parser/functions/getfromhash.rb index e948929d6..6e50ba14e 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 h.has_key?(key) + x = false + break + end + x = x[key] + keys_done << key end - return ans + return x end end # vim:set et: -- 2.20.1