Class: Zui::Platform

Inherits:
Struct
  • Object
show all
Defined in:
lib/zui/platform.rb

Constant Summary collapse

SUPPORTED_OSES =
%i[linux macos windows].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#archObject

Returns the value of attribute arch

Returns:

  • (Object)

    the current value of arch



6
7
8
# File 'lib/zui/platform.rb', line 6

def arch
  @arch
end

#osObject

Returns the value of attribute os

Returns:

  • (Object)

    the current value of os



6
7
8
# File 'lib/zui/platform.rb', line 6

def os
  @os
end

Class Method Details

.currentObject



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

Raises:

  • (ArgumentError)


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

#idObject



29
# File 'lib/zui/platform.rb', line 29

def id = "#{os}-#{arch}"

#linux?Boolean

Returns:

  • (Boolean)


30
# File 'lib/zui/platform.rb', line 30

def linux? = os == :linux

#macos?Boolean

Returns:

  • (Boolean)


31
# File 'lib/zui/platform.rb', line 31

def macos? = os == :macos

#supported?Boolean

Returns:

  • (Boolean)


28
# File 'lib/zui/platform.rb', line 28

def supported? = SUPPORTED_OSES.include?(os)

#windows?Boolean

Returns:

  • (Boolean)


32
# File 'lib/zui/platform.rb', line 32

def windows? = os == :windows