Module: Nanoc::Core::Utils Private

Defined in:
lib/nanoc/core/utils.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Utilities that don’t fit anywhere else.

Class Method Summary collapse

Class Method Details

.expand_path_without_drive_identifier(file_name, dir_string) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Same as File.expand_path, but does not add a drive identifier on Windows. This is necessary in case the path is a Nanoc path, rather than a filesystem path.



14
15
16
17
18
19
20
21
22
23
# File 'lib/nanoc/core/utils.rb', line 14

def self.expand_path_without_drive_identifier(file_name, dir_string)
  res = File.expand_path(file_name, dir_string)

  if windows_fs?
    # On Windows, strip the drive identifier, e.g. `C:`.
    res = res.sub(/^[A-Z]:/, '')
  end

  res
end

.windows_fs?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns ‘true` if absolute file paths start with a drive identifier, like `C:`.

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
# File 'lib/nanoc/core/utils.rb', line 26

def self.windows_fs?
  # NOTE: This isn’t memoized with ||= because @_windows_fs is a boolean.

  return @_windows_fs if defined?(@_windows_fs)

  absolute_path = File.expand_path('/a')
  @_windows_fs = absolute_path.start_with?(/^[A-Z]:/)

  @_windows_fs
end