Class: AssLauncher::Support::Platforms::PathnameExt

Inherits:
Pathname
  • Object
show all
Defined in:
lib/ass_launcher/support/platforms.rb

Overview

TODO:

TRANSLATE THIS:

Note:

Класс предназначен для унификации работы с путями ФС в различных ОС. ОС зависимые методы будут переопределены в классах потомках [UnixPath | WinPath | CygPath].

Пути могут приходить из следующих источников:

  • из консоли - при этом в Cygwin путь вида ‘/cygdrive/c’ будет непонятен за пределами Cygwin

  • из ENV - при этом путь \\host\share будет непонятен в Unix

Общая мысль в следующем:

  • пути приводятся к mixed_path - /cygwin/c -> C:/, C:\ -> C:/, \\host\share -> //host/share

  • переопределяется метод glob класса [Pathname] при этом метод в Cygwin будет иметь свою реализацию т.к. в cygwin Dirname.glob(‘C:/’) вернет пустой массив, а Dirname.glob(‘/cygdrive/c’) отработает правильно.

Parent for OS-specific *Path classes rubocop:disable AsciiComments rubocop:enable AsciiComments

Direct Known Subclasses

CygPath, UnixPath, WinPath

Defined Under Namespace

Classes: CygPath, UnixPath, WinPath

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ PathnameExt

Override constructor for lead path to (#mixed_path)

Parameters:

  • string (String)
    • string of path



159
160
161
162
# File 'lib/ass_launcher/support/platforms.rb', line 159

def initialize(string)
  @raw = string.to_s.strip
  super mixed_path(@raw)
end

Class Method Details

.glob(p1, *args) ⇒ Array<PathnameExt>

Override (Pathname.glob) method for correct work with windows paths like a ‘\\host\share’, ‘C:\’ and Cygwin paths like a ‘/cygdrive/c’

Returns:



188
189
190
# File 'lib/ass_launcher/support/platforms.rb', line 188

def self.glob(p1, *args)
  super p1.tr('\\', '/'), *args
end

Instance Method Details

#+(other) ⇒ Object

This is fix (bug or featere)? of [Pathname] method. Called in chiled clesses returns not childe class instance but returns

Pathname

instance



167
168
169
# File 'lib/ass_launcher/support/platforms.rb', line 167

def +(other)
  self.class.new(super(other).to_s)
end

#win_stringString

Return path suitable for windows apps. In Unix this method overridden

Returns:



180
181
182
# File 'lib/ass_launcher/support/platforms.rb', line 180

def win_string
  to_s.tr('/', '\\')
end