X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgrep.rb;fp=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgrep.rb;h=b6881bf365229b79b3b4b363b48fbceeea51a8e0;hb=131e09855e065be940e104d9ab0f18940cc76257;hp=c611a7e02d22acfd87e8a0a75d57892e0822ab78;hpb=407d322498f4fde815abf381007fbecfe5c10b2b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb b/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb index c611a7e02..b6881bf36 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb @@ -1,23 +1,26 @@ # # grep.rb # - module Puppet::Parser::Functions - newfunction(:grep, :type => :rvalue, :doc => <<-EOS -This function searches through an array and returns any elements that match -the provided regular expression. + newfunction(:grep, :type => :rvalue, :doc => <<-DOC + This function searches through an array and returns any elements that match + the provided regular expression. + + *Examples:* -*Examples:* + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') - grep(['aaa','bbb','ccc','aaaddd'], 'aaa') + Would return: -Would return: + ['aaa','aaaddd'] - ['aaa','aaaddd'] - EOS - ) do |arguments| + Note that since Puppet 4.0.0, the filter() function in Puppet can do the same: - if (arguments.size != 2) then + ['aaa', 'bbb', 'ccc', 'aaaddd']. filter |$x| { $x =~ 'aaa' } + DOC + ) do |arguments| + + if arguments.size != 2 raise(Puppet::ParseError, "grep(): Wrong number of arguments given #{arguments.size} for 2") end @@ -25,7 +28,6 @@ Would return: pattern = Regexp.new(arguments[1]) a.grep(pattern) - end end