Class: Mario::Platform

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

Defined Under Namespace

Classes: BSD, Cygwin, Darwin, Leopard, Linux, OperatingSystemNotRecognized, SnowLeopard, Solaris, Tiger, Windows7, WindowsNT

Constant Summary collapse

@@forced =
nil
@@logger =
nil
@@current =
nil

Class Method Summary collapse

Class Method Details

.check(klass) ⇒ true, false

Checks an os class against target_os

Returns:

  • (true, false)


85
86
87
# File 'lib/mario/platform.rb', line 85

def check(klass)
  target_os.downcase.include?(klass.target)
end

.check_group(group) ⇒ Class

Checks a list of possible operating system classes to see if their target os strings match the target_os value

Returns:

  • (Class)


68
69
70
71
72
73
# File 'lib/mario/platform.rb', line 68

def check_group(group)
  group.each do |klass|
    return klass if check(klass)
  end
  false
end

.check_symbol(name) ⇒ Object



136
137
138
# File 'lib/mario/platform.rb', line 136

def check_symbol(name)
  send(name.to_s + '?')
end

.currentOperatingSystem

Returns an instance of the current operating system class as determined by check_group against all operating system classes provided by targets

Returns:

  • (OperatingSystem)


118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/mario/platform.rb', line 118

def current
  # Search for the current target os
  current_target_klass = check_group(targets)
  unless current_target_klass
    raise OperatingSystemNotRecognized.new(<<-msg)

The current target os #{target_os}, is not recognized by Mario, please use/change Mario::Platform.forced to emulate a supported operating system."

msg
  end
  @@current ||= current_target_klass.new
  @@current
end

.darwin?Class

Checks if the current platform is part of the darwin_group and returns that class

Returns:

  • (Class)


61
62
63
# File 'lib/mario/platform.rb', line 61

def darwin?
  check_group(darwin_group)
end

.darwin_groupArray[Class]

A list of the different Darwin Versions

Returns:

  • (Array[Class])


30
31
32
33
34
# File 'lib/mario/platform.rb', line 30

def darwin_group
  # NOTE ordering required, but removal of Darwin class constant
  # procludes forcing os as Darwin
  [Tiger, Leopard, SnowLeopard, Darwin]
end

.forcedClass

Returns the value of the currently forced operating system class if any

Returns:

  • (Class)


102
103
104
# File 'lib/mario/platform.rb', line 102

def forced
  @@forced
end

.forced=(klass) ⇒ Object

Allows the user to force Mario to report the operating system as one of the provided operatin system classes



91
92
93
94
95
96
97
# File 'lib/mario/platform.rb', line 91

def forced=(klass)
  @@current=nil
  @@forced=klass
  logger.warn(<<-msg)
Mario::Platform.target_os will now report as '#{target_os}' and #{klass} will be used for all functionality including operating system checks, platform blocks, and hat based functionality
msg
end

.klass_to_method(klass) ⇒ Object



132
133
134
# File 'lib/mario/platform.rb', line 132

def klass_to_method(klass)
  klass.to_s.downcase.split('::').last
end

.logger(out = STDOUT) ⇒ Logger

Allows the setting of a logging mechanism, defaults to STDOUT

Returns:

  • (Logger)


109
110
111
112
# File 'lib/mario/platform.rb', line 109

def logger(out=STDOUT)
  @@logger ||= Logger.new(out)
  @@logger
end

.nix?Class

Checks if the current platform is part of the nix_group and returns that class

Returns:

  • (Class)


47
48
49
# File 'lib/mario/platform.rb', line 47

def nix?
  check_group(nix_group)
end

.nix_groupArray[Class]

A list of unix like operating system classes

Returns:

  • (Array[Class])


16
17
18
# File 'lib/mario/platform.rb', line 16

def nix_group
  [Cygwin, Linux, BSD, Solaris] + darwin_group
end

.target_osString

Returns:

  • (String)


78
79
80
# File 'lib/mario/platform.rb', line 78

def target_os
  @@forced ? @@forced.target : RbConfig::CONFIG['target_os']
end

.targetsArray[Class]

The union of the nix_group and windows_group operating system class sets, each operating system test method ( ie linux? ) is built from this set of class constants

Returns:

  • (Array[Class])


40
41
42
# File 'lib/mario/platform.rb', line 40

def targets
  nix_group | windows_group
end

.windows?Class

Checks if the current platform is part of the windows_group and returns that class

Returns:

  • (Class)


54
55
56
# File 'lib/mario/platform.rb', line 54

def windows?
  check_group(windows_group)
end

.windows_groupArray[Class]

A list of windows operating system classes

Returns:

  • (Array[Class])


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

def windows_group
  [Windows7, WindowsNT]
end