X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fstdlib%2Flib%2Fpuppet%2Fparser%2Ffunctions%2Fgrep.rb;h=2d274838ed6dd2b99bc40b554071c87b35ba2c64;hb=30caaa85aed7015ca0d77216bff175eebd917eb7;hp=ceba9ecc8ffc408f96dcaf1b3181c499713ea09b;hpb=ad88f67c13ae0f1a08936dad643f1e3509ab5f40;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 ceba9ecc8..2d274838e 100644 --- a/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb +++ b/3rdparty/modules/stdlib/lib/puppet/parser/functions/grep.rb @@ -1,32 +1,32 @@ # # 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. - -*Examples:* - - grep(['aaa','bbb','ccc','aaaddd'], 'aaa') - -Would return: - - ['aaa','aaaddd'] - EOS - ) do |arguments| - - if (arguments.size != 2) then - raise(Puppet::ParseError, "grep(): Wrong number of arguments "+ - "given #{arguments.size} for 2") + newfunction(:grep, :type => :rvalue, :doc => <<-DOC + @summary + This function searches through an array and returns any elements that match + the provided regular expression. + + @return + array of elements that match the provided regular expression. + @example Example Usage: + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') # Returns ['aaa','aaaddd'] + + > **Note:** that since Puppet 4.0.0, the built-in + [`filter`](https://puppet.com/docs/puppet/latest/function.html#filter) function does + the "same" - as any logic can be used to filter, as opposed to just regular expressions: + ```['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 a = arguments[0] pattern = Regexp.new(arguments[1]) a.grep(pattern) - end end