diff options
author | Travis Fields <travis@puppetlabs.com> | 2015-01-13 17:16:10 -0800 |
---|---|---|
committer | Travis Fields <travis@puppetlabs.com> | 2015-01-13 17:16:10 -0800 |
commit | ac3e51bac57ecc4b29965b5df5f10c2934b61cd0 (patch) | |
tree | 71413b757c0e0ec4d21727386979354e50099fdc /lib/puppet/parser/functions/concat.rb | |
parent | 80f09623b63cf6946b5913b629911e2c49b5d1dd (diff) | |
parent | 8db1f2e2f082cd688fa061fd6840cd0cea747232 (diff) |
Merge branch 'master' into 4.5.x
Diffstat (limited to 'lib/puppet/parser/functions/concat.rb')
-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 |