diff options
author | Brice Figureau <brice-puppet@daysofwonder.com> | 2009-11-10 16:43:37 +0100 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 75c32f910ea124a938a7035b3352c11a11b57d0c (patch) | |
tree | 744d30ad3c4234f57a92c417484a3b33685af99b /lib/puppet/parser/scope.rb | |
parent | 9122ac51284086a050d61df8fe060616aaf83d3c (diff) | |
download | puppet-75c32f910ea124a938a7035b3352c11a11b57d0c.tar.gz puppet-75c32f910ea124a938a7035b3352c11a11b57d0c.tar.xz puppet-75c32f910ea124a938a7035b3352c11a11b57d0c.zip |
Fix #2389 - Enhance Puppet DSL with Hashes
This bring a new container syntax to the Puppet DSL: hashes.
Hashes are defined like Ruby Hash:
{ key1 => val1, ... }
Hash keys are strings, but hash values can be any possible right
values admitted in Puppet DSL (ie function call, variables access...)
Currently it is possible:
1) to assign hashes to variable
$myhash = { key1 => "myval", key2 => $b }
2) to access hash members (recursively) from a variable containing
a hash (works for array too):
$myhash = { key => { subkey => "b" }}
notice($myhash[key][subjey]]
3) to use hash member access as resource title
4) to use hash in default definition parameter or resource parameter if
the type supports it (known for the moment).
It is not possible to string interpolate an hash access. If it proves
to be an issue it can be added or work-arounded with a string concatenation
operator easily.
It is not possible to use an hash as a resource title. This might be
possible once we support compound resource title.
Unlike the proposed syntax in the ticket it is not possible to assign
individual hash member (mostly to respect write once nature of variable
in puppet).
Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
Diffstat (limited to 'lib/puppet/parser/scope.rb')
-rw-r--r-- | lib/puppet/parser/scope.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/puppet/parser/scope.rb b/lib/puppet/parser/scope.rb index eda53a8cb..12c645a90 100644 --- a/lib/puppet/parser/scope.rb +++ b/lib/puppet/parser/scope.rb @@ -336,8 +336,11 @@ class Puppet::Parser::Scope # lookup the value in the scope if it exists and insert the var table[name] = lookupvar(name) # concatenate if string, append if array, nothing for other types - if value.is_a?(Array) + case value + when Array table[name] += value + when Hash + table[name].merge!(value) else table[name] << value end |