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)


81
82
83
# File 'lib/mario/platform.rb', line 81

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)


64
65
66
67
68
69
# File 'lib/mario/platform.rb', line 64

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

.check_symbol(name) ⇒ Object



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

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)


114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/mario/platform.rb', line 114

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)


57
58
59
# File 'lib/mario/platform.rb', line 57

def darwin?
  check_group(darwin_group)
end

.darwin_groupArray[Class]

A list of the different Darwin Versions

Returns:

  • (Array[Class])


26
27
28
29
30
# File 'lib/mario/platform.rb', line 26

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)


98
99
100
# File 'lib/mario/platform.rb', line 98

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



87
88
89
90
91
92
93
# File 'lib/mario/platform.rb', line 87

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



128
129
130
# File 'lib/mario/platform.rb', line 128

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)


105
106
107
108
# File 'lib/mario/platform.rb', line 105

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)


43
44
45
# File 'lib/mario/platform.rb', line 43

def nix?
  check_group(nix_group)
end

.nix_groupArray[Class]

A list of unix like operating system classes

Returns:

  • (Array[Class])


12
13
14
# File 'lib/mario/platform.rb', line 12

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

.target_osString

Returns:

  • (String)


74
75
76
# File 'lib/mario/platform.rb', line 74

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])


36
37
38
# File 'lib/mario/platform.rb', line 36

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)


50
51
52
# File 'lib/mario/platform.rb', line 50

def windows?
  check_group(windows_group)
end

.windows_groupArray[Class]

A list of windows operating system classes

Returns:

  • (Array[Class])


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

def windows_group
  [Windows7, WindowsNT]
end