summaryrefslogtreecommitdiff
path: root/lib/puppet
diff options
context:
space:
mode:
authorChris Edester <edestecd@miamioh.edu>2016-08-05 15:38:59 -0400
committerChris Edester <edestecd@miamioh.edu>2016-08-05 15:38:59 -0400
commit17a49baae33a78d6aa781aaaadafc08b43def040 (patch)
tree0fabeb603170308ab59fa3ddd58b2cc573219051 /lib/puppet
parent2bf9187cf8971fad35b0ffebf7c49963ba35c850 (diff)
Handle array values in join_keys_to_values function
Diffstat (limited to 'lib/puppet')
-rw-r--r--lib/puppet/parser/functions/join_keys_to_values.rb15
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/puppet/parser/functions/join_keys_to_values.rb b/lib/puppet/parser/functions/join_keys_to_values.rb
index e9924fe..e3baf9f 100644
--- a/lib/puppet/parser/functions/join_keys_to_values.rb
+++ b/lib/puppet/parser/functions/join_keys_to_values.rb
@@ -5,7 +5,8 @@
module Puppet::Parser::Functions
newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS
This function joins each key of a hash to that key's corresponding value with a
-separator. Keys and values are cast to strings. The return value is an array in
+separator. Keys are cast to strings. If values are arrays, multiple keys
+are added for each element. The return value is an array in
which each element is one joined key/value pair.
*Examples:*
@@ -13,6 +14,10 @@ which each element is one joined key/value pair.
join_keys_to_values({'a'=>1,'b'=>2}, " is ")
Would result in: ["a is 1","b is 2"]
+
+ join_keys_to_values({'a'=>1,'b'=>[2,3]}, " is ")
+
+Would result in: ["a is 1","b is 2","b is 3"]
EOS
) do |arguments|
@@ -38,8 +43,12 @@ Would result in: ["a is 1","b is 2"]
# Join the keys to their values.
hash.map do |k,v|
- String(k) + separator + String(v)
- end
+ if v.is_a?(Array)
+ v.map { |va| String(k) + separator + String(va) }
+ else
+ String(k) + separator + String(v)
+ end
+ end.flatten
end
end