Sha256: 53f914c0581bf85261f26b2303412f7828edc678972f57d7961cb6824d7be57d

Contents?: true

Size: 1.27 KB

Versions: 59

Compression:

Stored size: 1.27 KB

Contents

# frozen_string_literal: true

require 'pathname'

# Returns an array containing all of the filenames except for "." and ".." in the given directory.
Puppet::Functions.create_function(:'dir::children', Puppet::Functions::InternalFunction) do
  # @param dirname Absolute path or Puppet module name.
  # @return Array of files in the given directory.
  # @example List filenames from an absolute path.
  #   dir::children('/home/user/subdir/')
  # @example List filenames from a Puppet file path.
  #   dir::children('puppet_agent')
  dispatch :children do
    scope_param
    required_param 'String', :dirname
    return_type 'Array'
  end

  def children(scope, dirname)
    # Send Analytics Report
    Puppet.lookup(:bolt_executor) {}&.report_function_call(self.class.name)
    modname, subpath = dirname.split(File::SEPARATOR, 2)
    mod_path = scope.compiler.environment.module(modname)&.path

    full_mod_path = File.join(mod_path, subpath || '') if mod_path

    # Expand relative to the project directory if path is relative
    project = Puppet.lookup(:bolt_project)
    pathname = Pathname.new(dirname)
    full_dir = pathname.absolute? ? dirname : File.expand_path(File.join(project.path, dirname))

    # Sort for testability
    Dir.children(full_mod_path || full_dir).sort
  end
end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
bolt-3.29.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.28.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.27.4 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.27.2 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.27.1 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.26.2 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.26.1 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.25.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.24.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.23.1 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.23.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.22.1 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.22.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.21.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.20.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.19.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.18.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.17.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.16.1 bolt-modules/dir/lib/puppet/functions/dir/children.rb
bolt-3.16.0 bolt-modules/dir/lib/puppet/functions/dir/children.rb