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
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
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 |
.current ⇒ OperatingSystem
Returns an instance of the current operating system class as determined by check_group against all operating system classes provided by targets
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
61 62 63 |
# File 'lib/mario/platform.rb', line 61 def darwin? check_group(darwin_group) end |
.darwin_group ⇒ Array[Class]
A list of the different Darwin Versions
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 |
.forced ⇒ Class
Returns the value of the currently forced operating system class if any
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
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
47 48 49 |
# File 'lib/mario/platform.rb', line 47 def nix? check_group(nix_group) end |
.nix_group ⇒ Array[Class]
A list of unix like operating system classes
16 17 18 |
# File 'lib/mario/platform.rb', line 16 def nix_group [Cygwin, Linux, BSD, Solaris] + darwin_group end |
.target_os ⇒ String
78 79 80 |
# File 'lib/mario/platform.rb', line 78 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
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
54 55 56 |
# File 'lib/mario/platform.rb', line 54 def windows? check_group(windows_group) end |