37
|
1 #
|
|
2 # union.rb
|
|
3 #
|
|
4
|
|
5 module Puppet::Parser::Functions
|
|
6 newfunction(:union, :type => :rvalue, :doc => <<-EOS
|
|
7 This function returns a union of two arrays.
|
|
8
|
|
9 *Examples:*
|
|
10
|
|
11 union(["a","b","c"],["b","c","d"])
|
|
12
|
|
13 Would return: ["a","b","c","d"]
|
|
14 EOS
|
|
15 ) do |arguments|
|
|
16
|
|
17 # Two arguments are required
|
|
18 raise(Puppet::ParseError, "union(): Wrong number of arguments " +
|
|
19 "given (#{arguments.size} for 2)") if arguments.size != 2
|
|
20
|
|
21 first = arguments[0]
|
|
22 second = arguments[1]
|
|
23
|
|
24 unless first.is_a?(Array) && second.is_a?(Array)
|
|
25 raise(Puppet::ParseError, 'union(): Requires 2 arrays')
|
|
26 end
|
|
27
|
|
28 result = first | second
|
|
29
|
|
30 return result
|
|
31 end
|
|
32 end
|
|
33
|
|
34 # vim: set ts=2 sw=2 et :
|