Sha256: 0e2ebaed4a3aa3ade73de1e1c8eeb47d4dd6e824257a76407e77762aec15ede4

Contents?: true

Size: 1.25 KB

Versions: 32

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

# Finds an existing module and returns the path to its root directory.
#
# The argument to this function should be a module name String
# For example, the reference `mysql` will search for the
# directory `<MODULES DIRECTORY>/mysql` and return the first
# found on the modulepath.
#
# This function can also accept:
#
# * Multiple String arguments, which will return the path of the **first** module
#  found, skipping non existing modules.
# * An array of module names, which will return the path of the **first** module
#  found from the given names in the array, skipping non existing modules.
#
# The function returns `undef` if none of the given modules were found
#
# @since 5.4.0
#
Puppet::Functions.create_function(:module_directory, Puppet::Functions::InternalFunction) do
  dispatch :module_directory do
    scope_param
    repeated_param 'String', :names
  end

  dispatch :module_directory_array do
    scope_param
    repeated_param 'Array[String]', :names
  end

  def module_directory_array(scope, names)
    module_directory(scope, *names)
  end

  def module_directory(scope, *names)
    names.each do |module_name|
      found = scope.compiler.environment.module(module_name)
      return found.path if found
    end
    nil
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
puppet-8.10.0 lib/puppet/functions/module_directory.rb
puppet-8.10.0-x86-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.10.0-x64-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.10.0-universal-darwin lib/puppet/functions/module_directory.rb
puppet-8.9.0 lib/puppet/functions/module_directory.rb
puppet-8.9.0-x86-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.9.0-x64-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.9.0-universal-darwin lib/puppet/functions/module_directory.rb
puppet-8.8.1 lib/puppet/functions/module_directory.rb
puppet-8.8.1-x86-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.8.1-x64-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.8.1-universal-darwin lib/puppet/functions/module_directory.rb
puppet-8.7.0 lib/puppet/functions/module_directory.rb
puppet-8.7.0-x86-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.7.0-x64-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.7.0-universal-darwin lib/puppet/functions/module_directory.rb
puppet-8.6.0 lib/puppet/functions/module_directory.rb
puppet-8.6.0-x86-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.6.0-x64-mingw32 lib/puppet/functions/module_directory.rb
puppet-8.6.0-universal-darwin lib/puppet/functions/module_directory.rb