Class: Vagrant::ChefConfig::PathHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-chefconfig/path_helper.rb

Overview

Helper to deal with paths, mainly on Windows Borrowed from Chef 12 PathHelper class

Class Method Summary collapse

Class Method Details

.cleanpath(path) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/vagrant-chefconfig/path_helper.rb', line 17

def self.cleanpath(path)
  path = Pathname.new(path).cleanpath.to_s
  # ensure all forward slashes are backslashes
  if Gem.win_platform?
    path = path.gsub(File::SEPARATOR, path_separator)
  end
  path
end

.platform_specific_path(path) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/vagrant-chefconfig/path_helper.rb', line 6

def self.platform_specific_path(path)
  path = cleanpath(path)
  if Gem.win_platform?
    # \etc\chef\client.rb and \var\chef\client.rb -> C:/chef/client.rb
    if env['SYSTEMDRIVE'] && path[0] == '\\' && path.split('\\')[2] == 'chef'
      path = File.join(env['SYSTEMDRIVE'], path.split('\\', 3)[2])
    end
  end
  path
end