diff options
author | Hailee Kenney <hailee@puppetlabs.com> | 2013-05-15 13:56:15 -0700 |
---|---|---|
committer | Hailee Kenney <hailee@puppetlabs.com> | 2013-05-15 13:56:15 -0700 |
commit | a2abfb9894e8b91eeeffea0faa5d6e55a0519667 (patch) | |
tree | e13852080cd3a6f8aaae722ab13d2ae252802898 /lib/puppet/parser/functions/union.rb | |
parent | dad3a2948fb9ebc5c45975340bc8796c9c041d9a (diff) | |
parent | 737aa31546e71e9febea2199582510ef88a2560c (diff) |
Merge pull request #155 from AlexCline/feature/master/array_comparison_functions
(#20684) Add array comparison functions, difference, intersection and union
Diffstat (limited to 'lib/puppet/parser/functions/union.rb')
-rw-r--r-- | lib/puppet/parser/functions/union.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/puppet/parser/functions/union.rb b/lib/puppet/parser/functions/union.rb new file mode 100644 index 0000000..c91bb80 --- /dev/null +++ b/lib/puppet/parser/functions/union.rb @@ -0,0 +1,34 @@ +# +# union.rb +# + +module Puppet::Parser::Functions + newfunction(:union, :type => :rvalue, :doc => <<-EOS +This function returns a union of two arrays. + +*Examples:* + + union(["a","b","c"],["b","c","d"]) + +Would return: ["a","b","c","d"] + EOS + ) do |arguments| + + # Two arguments are required + raise(Puppet::ParseError, "union(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size != 2 + + first = arguments[0] + second = arguments[1] + + unless first.is_a?(Array) && second.is_a?(Array) + raise(Puppet::ParseError, 'union(): Requires 2 arrays') + end + + result = first | second + + return result + end +end + +# vim: set ts=2 sw=2 et : |