Module: PDK::Util
- Defined in:
- lib/pdk/util.rb,
lib/pdk/util/bundler.rb,
lib/pdk/util/version.rb
Defined Under Namespace
Class Method Summary collapse
-
.cachedir ⇒ String
Returns the fully qualified path to a per-user PDK cachedir.
-
.canonical_path(path) ⇒ String
Return an expanded, absolute path.
-
.find_upwards(target) ⇒ String?
Searches upwards from current working directory for the given target file.
-
.make_tmpdir_name(base) ⇒ String
Generate a name for a temporary directory.
-
.module_root ⇒ String?
Returns path to the root of the module being worked on.
Class Method Details
.cachedir ⇒ String
Returns the fully qualified path to a 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
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.(path) end end |
.find_upwards(target) ⇒ String?
Searches upwards from current working directory for the given target file.
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.(Dir.pwd) until !File.directory?(current) || current == previous filename = File.join(current, target) return filename if File.file?(filename) previous = current current = File.('..', current) end end |
.make_tmpdir_name(base) ⇒ String
Generate a name for a temporary directory.
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_root ⇒ String?
Returns path to the root of the module being worked on.
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 |