]> git.donarmstrong.com Git - dsa-puppet.git/blob - 3rdparty/modules/stdlib/lib/puppet/parser/functions/reject.rb
upgrade to stdlib 4.6.1
[dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / reject.rb
1 #
2 # reject.rb
3 #
4
5 module Puppet::Parser::Functions
6   newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args|
7 This function searches through an array and rejects all elements that match
8 the provided regular expression.
9
10 *Examples:*
11
12     reject(['aaa','bbb','ccc','aaaddd'], 'aaa')
13
14 Would return:
15
16     ['bbb','ccc']
17 EOS
18
19     if (args.size != 2)
20       raise Puppet::ParseError,
21         "reject(): Wrong number of arguments given #{args.size} for 2"
22     end
23
24     ary = args[0]
25     pattern = Regexp.new(args[1])
26
27     ary.reject { |e| e =~ pattern }
28   end
29 end
30
31 # vim: set ts=2 sw=2 et :