2013-02-12 16:07:18 +01:00
|
|
|
#
|
|
|
|
# concat.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:concat, :type => :rvalue, :doc => <<-EOS
|
2014-12-04 15:32:23 +01:00
|
|
|
Appends the contents of multiple arrays into array 1.
|
2013-02-12 16:07:18 +01:00
|
|
|
|
|
|
|
*Example:*
|
|
|
|
|
2014-12-04 15:32:23 +01:00
|
|
|
concat(['1','2','3'],['4','5','6'],['7','8','9'])
|
2013-02-12 16:07:18 +01:00
|
|
|
|
|
|
|
Would result in:
|
|
|
|
|
2014-12-04 15:32:23 +01:00
|
|
|
['1','2','3','4','5','6','7','8','9']
|
2013-02-12 16:07:18 +01:00
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
2014-12-04 15:33:23 +01:00
|
|
|
# Check that more than 2 arguments have been given ...
|
2013-02-12 16:07:18 +01:00
|
|
|
raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
|
2014-12-04 15:33:23 +01:00
|
|
|
"given (#{arguments.size} for < 2)") if arguments.size < 2
|
2013-02-12 16:07:18 +01:00
|
|
|
|
|
|
|
a = arguments[0]
|
|
|
|
|
2014-02-21 15:32:32 +01:00
|
|
|
# Check that the first parameter is an array
|
|
|
|
unless a.is_a?(Array)
|
2013-02-12 16:07:18 +01:00
|
|
|
raise(Puppet::ParseError, 'concat(): Requires array to work with')
|
|
|
|
end
|
|
|
|
|
2014-12-04 15:34:25 +01:00
|
|
|
result = a
|
|
|
|
arguments.shift
|
|
|
|
|
|
|
|
arguments.each do |x|
|
|
|
|
result = result + Array(x)
|
|
|
|
end
|
2013-02-12 16:07:18 +01:00
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|