diff options
author | Hunter Haugen <hunter@puppetlabs.com> | 2014-12-17 09:24:51 -0800 |
---|---|---|
committer | Hunter Haugen <hunter@puppetlabs.com> | 2014-12-17 09:24:51 -0800 |
commit | 8726caf996472c9c8822d1f697ff02a51abc54df (patch) | |
tree | 4d3da0a493ab38273d7c05272450ddeb2e3e604b /lib/puppet/parser | |
parent | 6237446582d71aa722b71ad8873f63c0662b20f7 (diff) | |
parent | 84bd98645f248a1dc3e0ed791e3af6f2ba9996fa (diff) | |
download | puppet-stdlib-8726caf996472c9c8822d1f697ff02a51abc54df.tar.gz puppet-stdlib-8726caf996472c9c8822d1f697ff02a51abc54df.tar.bz2 |
Merge pull request #374 from petems/MODULES-444-add_concat_multiple
MODULES-444-Add concat multiple
Diffstat (limited to 'lib/puppet/parser')
-rw-r--r-- | lib/puppet/parser/functions/concat.rb | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/puppet/parser/functions/concat.rb b/lib/puppet/parser/functions/concat.rb index 0d35b07..618e62d 100644 --- a/lib/puppet/parser/functions/concat.rb +++ b/lib/puppet/parser/functions/concat.rb @@ -4,31 +4,35 @@ module Puppet::Parser::Functions newfunction(:concat, :type => :rvalue, :doc => <<-EOS -Appends the contents of array 2 onto array 1. +Appends the contents of multiple arrays into array 1. *Example:* - concat(['1','2','3'],['4','5','6']) + concat(['1','2','3'],['4','5','6'],['7','8','9']) Would result in: - ['1','2','3','4','5','6'] + ['1','2','3','4','5','6','7','8','9'] EOS ) do |arguments| - # Check that 2 arguments have been given ... + # Check that more than 2 arguments have been given ... raise(Puppet::ParseError, "concat(): Wrong number of arguments " + - "given (#{arguments.size} for 2)") if arguments.size != 2 + "given (#{arguments.size} for < 2)") if arguments.size < 2 a = arguments[0] - b = arguments[1] # Check that the first parameter is an array unless a.is_a?(Array) raise(Puppet::ParseError, 'concat(): Requires array to work with') end - result = a + Array(b) + result = a + arguments.shift + + arguments.each do |x| + result = result + Array(x) + end return result end |