Class: Zui::Platform
- Inherits:
-
Struct
- Object
- Struct
- Zui::Platform
- Defined in:
- lib/zui/platform.rb
Constant Summary collapse
- SUPPORTED_OSES =
%i[linux macos windows].freeze
Instance Attribute Summary collapse
-
#arch ⇒ Object
Returns the value of attribute arch.
-
#os ⇒ Object
Returns the value of attribute os.
Class Method Summary collapse
Instance Method Summary collapse
- #assert_supported! ⇒ Object
- #id ⇒ Object
- #linux? ⇒ Boolean
- #macos? ⇒ Boolean
- #supported? ⇒ Boolean
- #windows? ⇒ Boolean
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch
6 7 8 |
# File 'lib/zui/platform.rb', line 6 def arch @arch end |
#os ⇒ Object
Returns the value of attribute os
6 7 8 |
# File 'lib/zui/platform.rb', line 6 def os @os end |
Class Method Details
.current ⇒ Object
9 10 11 |
# File 'lib/zui/platform.rb', line 9 def self.current detect(RbConfig::CONFIG.fetch("host_os"), RbConfig::CONFIG.fetch("host_cpu")) end |
.detect(host_os, host_cpu) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/zui/platform.rb', line 13 def self.detect(host_os, host_cpu) os = case host_os.to_s when /darwin|mac\s?os/i then :macos when /linux/i then :linux when /mswin|mingw|cygwin|windows/i then :windows else :unsupported end arch = case host_cpu.to_s when /aarch64|arm64/i then :arm64 when /x86_64|amd64|x64/i then :x86_64 else host_cpu.to_s.downcase.gsub(/[^a-z0-9_]+/, "_").to_sym end new(os:, arch:) end |
Instance Method Details
#assert_supported! ⇒ Object
34 35 36 37 38 |
# File 'lib/zui/platform.rb', line 34 def assert_supported! return self if supported? raise ArgumentError, "Zui desktop applications support Linux, macOS, and Windows; detected #{os}/#{arch}" end |
#id ⇒ Object
29 |
# File 'lib/zui/platform.rb', line 29 def id = "#{os}-#{arch}" |
#linux? ⇒ Boolean
30 |
# File 'lib/zui/platform.rb', line 30 def linux? = os == :linux |
#macos? ⇒ Boolean
31 |
# File 'lib/zui/platform.rb', line 31 def macos? = os == :macos |
#supported? ⇒ Boolean
28 |
# File 'lib/zui/platform.rb', line 28 def supported? = SUPPORTED_OSES.include?(os) |
#windows? ⇒ Boolean
32 |
# File 'lib/zui/platform.rb', line 32 def windows? = os == :windows |