2013-05-13 18:09:33 +02:00
|
|
|
#
|
|
|
|
# union.rb
|
|
|
|
#
|
|
|
|
|
|
|
|
module Puppet::Parser::Functions
|
|
|
|
newfunction(:union, :type => :rvalue, :doc => <<-EOS
|
2015-08-24 13:01:29 +02:00
|
|
|
This function returns a union of two or more arrays.
|
2013-05-13 18:09:33 +02:00
|
|
|
|
|
|
|
*Examples:*
|
|
|
|
|
|
|
|
union(["a","b","c"],["b","c","d"])
|
|
|
|
|
|
|
|
Would return: ["a","b","c","d"]
|
|
|
|
EOS
|
|
|
|
) do |arguments|
|
|
|
|
|
2015-08-24 13:01:29 +02:00
|
|
|
# Check that 2 or more arguments have been given ...
|
2013-05-13 18:09:33 +02:00
|
|
|
raise(Puppet::ParseError, "union(): Wrong number of arguments " +
|
2015-08-24 13:01:29 +02:00
|
|
|
"given (#{arguments.size} for < 2)") if arguments.size < 2
|
2013-05-13 18:09:33 +02:00
|
|
|
|
2015-08-24 13:01:29 +02:00
|
|
|
arguments.each do |argument|
|
|
|
|
raise(Puppet::ParseError, 'union(): Every parameter must be an array') unless argument.is_a?(Array)
|
2013-05-13 18:09:33 +02:00
|
|
|
end
|
|
|
|
|
2015-08-24 13:01:29 +02:00
|
|
|
arguments.reduce(:|)
|
2013-05-13 18:09:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# vim: set ts=2 sw=2 et :
|