Class: Mario::Platform
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
-
.check(klass) ⇒ true, false
Checks an os class against Platform.target_os.
-
.check_group(group) ⇒ Class
Checks a list of possible operating system classes to see if their target os strings match the Platform.target_os value.
- .check_symbol(name) ⇒ Object
-
.current ⇒ OperatingSystem
Returns an instance of the current operating system class as determined by Platform.check_group against all operating system classes provided by Platform.targets.
-
.darwin? ⇒ Class
Checks if the current platform is part of the Platform.darwin_group and returns that class.
-
.darwin_group ⇒ Array[Class]
A list of the different Darwin Versions.
-
.forced ⇒ Class
Returns the value of the currently forced operating system class if any.
-
.forced=(klass) ⇒ Object
Allows the user to force Mario to report the operating system as one of the provided operatin system classes.
- .klass_to_method(klass) ⇒ Object
-
.logger(out = STDOUT) ⇒ Logger
Allows the setting of a logging mechanism, defaults to STDOUT.
-
.nix? ⇒ Class
Checks if the current platform is part of the Platform.nix_group and returns that class.
-
.nix_group ⇒ Array[Class]
A list of unix like operating system classes.
- .target_os ⇒ String
-
.targets ⇒ Array[Class]
The union of the Platform.nix_group and Platform.windows_group operating system class sets, each operating system test method ( ie linux? ) is built from this set of class constants.
-
.windows? ⇒ Class
Checks if the current platform is part of the Platform.windows_group and returns that class.
-
.windows_group ⇒ Array[Class]
A list of windows operating system classes.
Class Method Details
.check(klass) ⇒ true, false
Checks an os class against target_os
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
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 |
.current ⇒ OperatingSystem
Returns an instance of the current operating system class as determined by check_group against all operating system classes provided by targets
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
57 58 59 |
# File 'lib/mario/platform.rb', line 57 def darwin? check_group(darwin_group) end |
.darwin_group ⇒ Array[Class]
A list of the different Darwin Versions
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 |
.forced ⇒ Class
Returns the value of the currently forced operating system class if any
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
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
43 44 45 |
# File 'lib/mario/platform.rb', line 43 def nix? check_group(nix_group) end |
.nix_group ⇒ Array[Class]
A list of unix like operating system classes
12 13 14 |
# File 'lib/mario/platform.rb', line 12 def nix_group [Cygwin, Linux, BSD, Solaris] + darwin_group end |
.target_os ⇒ String
74 75 76 |
# File 'lib/mario/platform.rb', line 74 def target_os @@forced ? @@forced.target : RbConfig::CONFIG['target_os'] end |
.targets ⇒ Array[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
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
50 51 52 |
# File 'lib/mario/platform.rb', line 50 def windows? check_group(windows_group) end |