view modules/stdlib/lib/puppet/parser/functions/union.rb @ 272:c42fb28cff86

Update to a newer Python module This also pulls in an EPEL module (which we don't use) and a newer stdlib version.
author IBBoard <dev@ibboard.co.uk>
date Fri, 03 Jan 2020 19:56:04 +0000
parents addb0ea390a1
children d9352a684e62
line wrap: on
line source

#
# union.rb
#
module Puppet::Parser::Functions
  newfunction(:union, :type => :rvalue, :doc => <<-DOC
    This function returns a union of two or more arrays.

    *Examples:*

        union(["a","b","c"],["b","c","d"])

    Would return: ["a","b","c","d"]
    DOC
             ) do |arguments|

    # Check that 2 or more arguments have been given ...
    raise(Puppet::ParseError, "union(): Wrong number of arguments given (#{arguments.size} for < 2)") if arguments.size < 2

    arguments.each do |argument|
      raise(Puppet::ParseError, 'union(): Every parameter must be an array') unless argument.is_a?(Array)
    end

    arguments.reduce(:|)
  end
end

# vim: set ts=2 sw=2 et :