Module: PDK::Util

Defined in:
lib/pdk/util.rb,
lib/pdk/util/bundler.rb,
lib/pdk/util/version.rb

Defined Under Namespace

Modules: Bundler, Version

Class Method Summary collapse

Class Method Details

.cachedirString

Returns the fully qualified path to a per-user PDK cachedir.

Returns:

  • (String)

    Fully qualified path to per-user PDK cachedir.



56
57
58
59
60
61
62
63
64
# File 'lib/pdk/util.rb', line 56

def cachedir
  basedir = if Gem.win_platform?
              ENV['LOCALAPPDATA']
            else
              Dir.home
            end

  File.join(basedir, '.pdk', 'cache')
end

.canonical_path(path) ⇒ String

Return an expanded, absolute path

Parameters:

  • path (String)

    Existing path that may not be canonical

Returns:

  • (String)

    Canonical path



41
42
43
44
45
46
47
48
49
50
# File 'lib/pdk/util.rb', line 41

def canonical_path(path)
  if Gem.win_platform?
    unless File.exist?(path)
      raise PDK::CLI::FatalError, _("Cannot resolve a full path to '%{path}' as it does not currently exist") % { path: path }
    end
    Puppet::Util::Windows::File.get_long_pathname(path)
  else
    File.expand_path(path)
  end
end

.find_upwards(target) ⇒ String?

Searches upwards from current working directory for the given target file.

Parameters:

  • target (String)

    Name of file to search for.

Returns:

  • (String, nil)

    Fully qualified path to the given target file if found, nil if the target file could not be found.



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/pdk/util.rb', line 13

def find_upwards(target)
  previous = nil
  current  = File.expand_path(Dir.pwd)

  until !File.directory?(current) || current == previous
    filename = File.join(current, target)
    return filename if File.file?(filename)
    previous = current
    current = File.expand_path('..', current)
  end
end

.make_tmpdir_name(base) ⇒ String

Generate a name for a temporary directory.

Parameters:

  • base (String)

    A string to base the name generation off.

Returns:

  • (String)

    The temporary directory path.



31
32
33
# File 'lib/pdk/util.rb', line 31

def make_tmpdir_name(base)
  Dir::Tmpname.make_tmpname(File.join(Dir.tmpdir, base), nil)
end

.module_rootString?

Returns path to the root of the module being worked on.

Returns:

  • (String, nil)

    Fully qualified base path to module, or nil if the current working dir does not appear to be within a module.



71
72
73
74
75
76
77
78
# File 'lib/pdk/util.rb', line 71

def module_root
   = find_upwards('metadata.json')
  if 
    File.dirname()
  else
    nil
  end
end