Class: Platform

Inherits:
Object show all
Defined in:
lib/pmsrb/platform.rb

Overview

Helper functions for determining platform Usage:

Platform.short_name => osx/windows/linux, depending on your current platform

Platform.new("mswin").short_name => windows, since we are creating an instance.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform = PLATFORM) ⇒ Platform

Returns a new instance of Platform.



55
56
57
# File 'lib/pmsrb/platform.rb', line 55

def initialize(platform = PLATFORM)
  @platform = platform
end

Class Method Details

.linuxObject



15
16
17
# File 'lib/pmsrb/platform.rb', line 15

def self.linux
  yield if(linux?)
end

.linux?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/pmsrb/platform.rb', line 27

def self.linux?
	PLATFORM =~ /linux/
end

.macObject



7
8
9
# File 'lib/pmsrb/platform.rb', line 7

def self.mac
  yield if(mac?)
end

.mac?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/pmsrb/platform.rb', line 19

def self.mac?
  PLATFORM =~ /darwin/
end

.preferred_archiveObject



43
44
45
46
47
48
49
# File 'lib/pmsrb/platform.rb', line 43

def self.preferred_archive
  if(windows?)
    "zip"
  else
    "tgz"
  end
end

.short_nameObject



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pmsrb/platform.rb', line 31

def self.short_name
 if(mac?)
   "osx"
  elsif(windows?)
    "windows"
  elsif(linux?)
    "linux"
  else
    "unknown"
  end
end

.supportedObject



51
52
53
# File 'lib/pmsrb/platform.rb', line 51

def self.supported
  %w(darwin mswin linux).collect {|x| Platform.new(x)}
end

.windowsObject



11
12
13
# File 'lib/pmsrb/platform.rb', line 11

def self.windows
  yield if(windows?)
end

.windows?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pmsrb/platform.rb', line 23

def self.windows?
  PLATFORM =~ /mswin/
end

Instance Method Details

#linux?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/pmsrb/platform.rb', line 67

def linux?
  @platform =~ /linux/
end

#mac?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/pmsrb/platform.rb', line 59

def mac?
  @platform =~ /darwin/
end

#short_nameObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/pmsrb/platform.rb', line 71

def short_name
 if(mac?)
   "osx"
  elsif(windows?)
    "windows"
  elsif(linux?)
    "linux"
  else
    "unknown"
  end
end

#windows?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/pmsrb/platform.rb', line 63

def windows?
  @platform =~ /mswin/
end