Suggest different variables to use if we want to tunnel both v4 and v6
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / lib / puppet / parser / functions / grep.rb
1 #
2 # grep.rb
3 #
4 module Puppet::Parser::Functions
5   newfunction(:grep, :type => :rvalue, :doc => <<-DOC
6     This function searches through an array and returns any elements that match
7     the provided regular expression.
8
9     *Examples:*
10
11         grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
12
13     Would return:
14
15         ['aaa','aaaddd']
16
17     Note that since Puppet 4.0.0, the filter() function in Puppet can do the same:
18
19         ['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' }
20     DOC
21              ) do |arguments|
22
23     if arguments.size != 2
24       raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2")
25     end
26
27     a = arguments[0]
28     pattern = Regexp.new(arguments[1])
29
30     a.grep(pattern)
31   end
32 end
33
34 # vim: set ts=2 sw=2 et :