source: other-projects/hathitrust/vagrant-solr-cluster/trunk/modules/stdlib/lib/puppet/parser/functions/grep.rb@ 30960

Last change on this file since 30960 was 30960, checked in by davidb, 8 years ago

Switch to using Puppet to provision machine. Strongly based on files developed for spark-hdfs cluster

File size: 609 bytes
Line 
1#
2# grep.rb
3#
4
5module Puppet::Parser::Functions
6 newfunction(:grep, :type => :rvalue, :doc => <<-EOS
7This function searches through an array and returns any elements that match
8the provided regular expression.
9
10*Examples:*
11
12 grep(['aaa','bbb','ccc','aaaddd'], 'aaa')
13
14Would return:
15
16 ['aaa','aaaddd']
17 EOS
18 ) do |arguments|
19
20 if (arguments.size != 2) then
21 raise(Puppet::ParseError, "grep(): Wrong number of arguments "+
22 "given #{arguments.size} for 2")
23 end
24
25 a = arguments[0]
26 pattern = Regexp.new(arguments[1])
27
28 a.grep(pattern)
29
30 end
31end
32
33# vim: set ts=2 sw=2 et :
Note: See TracBrowser for help on using the repository browser.