Class: KXI::Platform
- Inherits:
-
Object
- Object
- KXI::Platform
- Defined in:
- lib/kxi/platform.rb
Overview
Represents an platform of execution
Constant Summary collapse
- WINDOWS =
Microsoft Windows
'windows'
- OSX =
Apple macOS
'osx'
- LINUX =
Linux-based system
'linux'
- @@this =
nil
Class Method Summary collapse
-
.env(key) ⇒ string
Gets an environment variable.
-
.this ⇒ KXI::Platform
Gets the current platform.
Instance Method Summary collapse
-
#directory_separator ⇒ string
Gets the separator of directories within a path.
-
#exec(name, *dir) ⇒ string?
Finds an executable within the PATH of platform.
-
#initialize(nm, ver, ds, ps, cs, *libs) ⇒ Platform
constructor
Instantiates the Platform class.
-
#library_extensions ⇒ Array<string>
Gets the file extensions of libraries.
-
#name ⇒ string
Gets the name of platform.
-
#path_case_sensitive? ⇒ bool
Determines whether paths are case-sensitive.
-
#path_separator ⇒ string
Gets the separator of paths.
-
#version ⇒ KXI::Application::Version
Gets the version of platform.
Constructor Details
#initialize(nm, ver, ds, ps, cs, *libs) ⇒ Platform
Instantiates the KXI::Platform class
57 58 59 60 61 62 63 64 |
# File 'lib/kxi/platform.rb', line 57 def initialize(nm, ver, ds, ps, cs, *libs) @name = nm @version = KXI::Application::Version.parse(ver) @ds = ds @ps = ps @cs = cs @libs = libs end |
Class Method Details
.env(key) ⇒ string
Gets an environment variable
96 97 98 99 100 101 102 |
# File 'lib/kxi/platform.rb', line 96 def self.env(key) key = key.downcase ENV.each_pair do |k, v| return v if k.downcase == key end return nil end |
.this ⇒ KXI::Platform
Gets the current platform
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/kxi/platform.rb', line 68 def self.this return @@this if @@this != nil if /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM @@this = Platform.new(WINDOWS, `wmic os get Version /value`.split('=').last.strip.chomp, '\\', ';', false, 'dll') elsif /darwin/ =~ RUBY_PLATFORM @@this = Platform.new(OSX, `defaults read loginwindow SystemVersionStampAsString`, '/', ':', true, 'dylib') else @@this = Platform.new(LINUX, `uname -r`.split('-')[0], '/', ':', true, 'so') end return @@this end |
Instance Method Details
#directory_separator ⇒ string
Gets the separator of directories within a path
40 41 42 |
# File 'lib/kxi/platform.rb', line 40 def directory_separator @ds end |
#exec(name, *dir) ⇒ string?
Finds an executable within the PATH of platform
82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/kxi/platform.rb', line 82 def exec(name, *dir) dir = Platform.env('path').split(@ps) if dir.length == 0 ext = Platform.env('pathext') (ext != nil ? ext.split(@ps) + [''] : ['']).each do |e| dir.each do |d| f = File.join(d, "#{name}#{e}") return f if File.exists?(f) end end return nil end |
#library_extensions ⇒ Array<string>
Gets the file extensions of libraries
28 29 30 |
# File 'lib/kxi/platform.rb', line 28 def library_extensions @libs end |
#name ⇒ string
Gets the name of platform
16 17 18 |
# File 'lib/kxi/platform.rb', line 16 def name @name end |
#path_case_sensitive? ⇒ bool
Determines whether paths are case-sensitive
46 47 48 |
# File 'lib/kxi/platform.rb', line 46 def path_case_sensitive? @cs end |
#path_separator ⇒ string
Gets the separator of paths
34 35 36 |
# File 'lib/kxi/platform.rb', line 34 def path_separator @ps end |
#version ⇒ KXI::Application::Version
Gets the version of platform
22 23 24 |
# File 'lib/kxi/platform.rb', line 22 def version @version end |