Module: Berkshelf::Mixin::PathHelpers

Included in:
Chef::Config
Defined in:
lib/berkshelf/mixin/path_helpers.rb

Overview

Author:

Instance Method Summary collapse

Instance Method Details

#platform_specific_path(path) ⇒ String

Converts a path to a path usable for your current platform

Parameters:

Returns:



9
10
11
12
13
14
15
16
# File 'lib/berkshelf/mixin/path_helpers.rb', line 9

def platform_specific_path(path)
  if RUBY_PLATFORM =~ /mswin|mingw|windows/
    system_drive = ENV['SYSTEMDRIVE'] ? ENV['SYSTEMDRIVE'] : ""
    path         = win_slashify File.join(system_drive, path.split('/')[2..-1])
  end

  path
end

#win_slashify(path) ⇒ String

Convert a unixy filepath to a windowsy filepath. Swaps forward slashes for double backslashes

Parameters:

  • path (String)

    filepath to convert

Returns:

  • (String)

    converted filepath



26
27
28
# File 'lib/berkshelf/mixin/path_helpers.rb', line 26

def win_slashify(path)
  path.gsub(File::SEPARATOR, (File::ALT_SEPARATOR || '\\'))
end