Sha256: 4a362b6e68253f0f65f0b10dd1b18f7266291d06c117cf7c0deb10402a4d24fd

Contents?: true

Size: 1.25 KB

Versions: 19

Compression:

Stored size: 1.25 KB

Contents

# @summary Take one or more paths and join them together using the os specific separator.
# Because in how windows uses a different separator this function
# will format a windows path into a equilivent unix like path.  This type of unix like
# path will work on windows.
#
# @param dirs Joins two or more directories by file separator.
# @return [Stdlib::Absolutepath] The joined path
# @example Joining Unix paths to return `/tmp/test/libs`
#   extlib::path_join('/tmp', 'test', 'libs')
# @example Joining Windows paths to return `/c/test/libs`
#   extlib::path_join('c:', 'test', 'libs')
function extlib::path_join(Array[String] $dirs) >> Stdlib::Absolutepath {
  $unix_sep = '/'
  $sep_regex = /\/|\\/
  $first_value = $dirs[0]
  # when first value is absolute path, append all other elements
  # by breaking the path into pieces first, then joining
  if $first_value =~ Stdlib::Absolutepath {
    $fixed_dirs = $first_value.split($sep_regex) + $dirs.delete($first_value)
  } else {
    $fixed_dirs = $dirs
  }
  $no_empty_dirs = $fixed_dirs.filter |$dir| { !empty($dir) }
  $dirs_without_sep = $no_empty_dirs.map |String $dir | {
    # remove : and file separator
    $dir.regsubst($sep_regex, '').regsubst(':', '')
  }
  join([$unix_sep,$dirs_without_sep.join($unix_sep)])
}

Version data entries

19 entries across 19 versions & 1 rubygems

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