Sha256: e8ff0b24f8abae69d8b3477364fd438345ba3bbd24f1e828d1aec52dee07e8c2

Contents?: true

Size: 1.1 KB

Versions: 19

Compression:

Stored size: 1.1 KB

Contents

# @summary Splits the given directory or directories into individual paths.
#
# Use this function when you need to split a absolute path into multiple absolute paths
# that all descend from the given path.
#
# @param dirs [Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]]] - either an absolute path or a array of absolute paths.
# @return [Array[String]] - an array of absolute paths after being cut into individual paths.
# @example calling the function
#  extlib::dir_split('/opt/puppetlabs') => ['/opt', '/opt/puppetlabs']
function extlib::dir_split(Variant[Stdlib::Absolutepath, Array[Stdlib::Absolutepath]] $dirs) >> Array[String] {
  $sep = extlib::file_separator()

  $dirs_array = [$dirs].flatten.unique.map | Stdlib::Absolutepath $dir | {
    $dir.split(shell_escape($sep)).reduce([]) |Array $acc, $value  | {
        $counter = $acc.length - 1
        $acc_value = ($acc[$counter] =~ Undef) ? { true => '', false => $acc[$counter] }
        unless empty($value) {
          $acc + extlib::path_join([$acc_value, $value])
        } else {
          $acc
        }
      }
  }
  $dirs_array.flatten.unique
}

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
puppet-debugger-1.4.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-1.3.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-1.2.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-1.1.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-1.0.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.19.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.18.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.17.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.16.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.15.2 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.15.1 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.15.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.14.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.13.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.12.3 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.12.2 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.12.1 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.12.0 spec/fixtures/modules/extlib/functions/dir_split.pp
puppet-debugger-0.11.0 spec/fixtures/modules/extlib/functions/dir_split.pp