]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/concat.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / concat.rb
1 #
2 # concat.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:concat, :type => :rvalue, :doc => <<-EOS
7 Appends the contents of multiple arrays into array 1.
8
9 *Example:*
10
11     concat(['1','2','3'],['4','5','6'],['7','8','9'])
12
13 Would result in:
14
15   ['1','2','3','4','5','6','7','8','9']
16     EOS
17   ) do |arguments|
18
19     # Check that more than 2 arguments have been given ...
20     raise(Puppet::ParseError, "concat(): Wrong number of arguments " +
21       "given (#{arguments.size} for < 2)") if arguments.size < 2
22
23     a = arguments[0]
24
25     # Check that the first parameter is an array
26     unless a.is_a?(Array)
27       raise(Puppet::ParseError, 'concat(): Requires array to work with')
28     end
29
30     result = a
31     arguments.shift
32
33     arguments.each do |x|
34       result = result + Array(x)
35     end
36
37     return result
38   end
39 end
40
41 # vim: set ts=2 sw=2 et :