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