Puppet Function: xdmod::member_substring

Defined in:
lib/puppet/functions/xdmod/member_substring.rb
Function type:
Ruby 4.x API

Overview

xdmod::member_substring(Array $array, String $substring)String

Function to test member substring

Examples:

Return present

member(['nfsclient.bytes.write.server','infiniband.hca.type'], '^nfsclient')

Return absent

member(['nfsclient.bytes.write.server','nfsclient.bytes.write.server'], '^infiniband')

Parameters:

  • array (Array)

    The array to check.

  • substring (String)

    The substring used for check.

Returns:

  • (String)

    Returns present if substring in array

  • (String)

    Returns absent if substring not in array



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/puppet/functions/xdmod/member_substring.rb', line 4

Puppet::Functions.create_function(:'xdmod::member_substring') do
  # Function to test member substring
  # @param array The array to check.
  # @param substring The substring used for check.
  # @return [String] Returns `present` if substring in array
  # @return [String] Returns `absent` if substring not in array
  # @example Return `present`
  #   member(['nfsclient.bytes.write.server','infiniband.hca.type'], '^nfsclient')
  # @example Return `absent`
  #   member(['nfsclient.bytes.write.server','nfsclient.bytes.write.server'], '^infiniband')
  dispatch :check do
    param 'Array', :array
    param 'String', :substring
  end

  def check(array, substring)
    match = array.any? do |a|
      a =~ %r{#{substring}}
    end

    return 'present' if match

    'absent'
  end
end