Module: AssLauncher::Support::Platforms

Overview

OS-specific things Mixin module help work with things as paths and env in other plases

Examples:

include AssLauncher::Support::Platforms

if cigwin?
  #do if run in Cygwin
end

# Find env value on regex
pf = platform.env[/program\s*files/i]
return if pf.size == 0

# Use #path
p = platform.path(pf[0])
p.exists?

# Use #path_class
platform.path_class.glob('C:/*').each do |path|
  path.exists?
end

# Use #glob directly
platform.glob('C:/*').each do |path|
  path.exists?
end

Defined Under Namespace

Classes: CygEnv, PathnameExt, UnixEnv, WinEnv

Class Method Summary collapse

Class Method Details

.cygwin?Boolean

True if run in Cygwin

Returns:

  • (Boolean)


84
85
86
# File 'lib/ass_launcher/support/platforms.rb', line 84

def cygwin?
  Platform.cygwin?
end

.envUnixEnv | WinEnv | CygEnv

Return suitable class

Returns:



241
242
243
244
245
246
247
248
249
# File 'lib/ass_launcher/support/platforms.rb', line 241

def self.env
  if cygwin?
    CygEnv
  elsif windows?
    WinEnv
  else
    UnixEnv
  end
end

.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:



129
130
131
# File 'lib/ass_launcher/support/platforms.rb', line 129

def self.glob(p1, *args)
  path_class.glob(p1, *args)
end

.linux?Boolean

True if run in Linux

Returns:

  • (Boolean)


96
97
98
# File 'lib/ass_launcher/support/platforms.rb', line 96

def linux?
  Platform.linux?
end

.path(string) ⇒ UnixPath | WinPath | CygPath

Return suitable class instance

Returns:

  • (UnixPath | WinPath | CygPath)


124
125
126
# File 'lib/ass_launcher/support/platforms.rb', line 124

def self.path(string)
  path_class.new(string)
end

.path_classUnixPath | WinPath | CygPath

Return suitable class

Returns:

  • (UnixPath | WinPath | CygPath)


112
113
114
115
116
117
118
119
120
# File 'lib/ass_launcher/support/platforms.rb', line 112

def self.path_class
  if cygwin?
    PathnameExt::CygPath
  elsif windows?
    PathnameExt::WinPath
  else
    PathnameExt::UnixPath
  end
end

.windows?Boolean

True if run in MinGW

Returns:

  • (Boolean)


90
91
92
# File 'lib/ass_launcher/support/platforms.rb', line 90

def windows?
  Platform.windows?
end