Module: GDK::Machine

Defined in:
lib/gdk/machine.rb

Overview

Provides information about the machine

Constant Summary collapse

ARM64_VARIATIONS =
%w[arm64 aarch64].freeze

Class Method Summary collapse

Class Method Details

.architectureString

The CPU architecture of the machine

Returns:

  • (String)

    the cpu architecture



67
68
69
# File 'lib/gdk/machine.rb', line 67

def self.architecture
  RbConfig::CONFIG['target_cpu']
end

.arm64?Boolean

Is the machine running on an ARM64 processor?

Returns:

  • (Boolean)

    whether current architecture is using ARM64 architecture



39
40
41
# File 'lib/gdk/machine.rb', line 39

def self.arm64?
  ARM64_VARIATIONS.any?(architecture)
end

.linux?Boolean

Is the machine running Linux?

Returns:

  • (Boolean)

    whether we are in a Linux machine



11
12
13
# File 'lib/gdk/machine.rb', line 11

def self.linux?
  platform == 'linux'
end

.macos?Boolean

Is the machine running MacOS?

Returns:

  • (Boolean)

    whether we are in a MacOS machine



18
19
20
# File 'lib/gdk/machine.rb', line 18

def self.macos?
  platform == 'darwin'
end

.platformString

The kernel type the machine is running on

Returns:

  • (String)

    darwin, linux, unknown



53
54
55
56
57
58
59
60
61
62
# File 'lib/gdk/machine.rb', line 53

def self.platform
  case RbConfig::CONFIG['host_os']
  when /darwin/i
    'darwin'
  when /linux/i
    'linux'
  else
    'unknown'
  end
end

.supported?Boolean

Is the machine running a supported OS?

Returns:

  • (Boolean)

    whether we are running a supported OS



32
33
34
# File 'lib/gdk/machine.rb', line 32

def self.supported?
  platform != 'unknown'
end

.wsl?Boolean

Is the machine running on Windows Subsystem for Linux?

Returns:

  • (Boolean)

    whether we run Linux using Windows Subsystem for Linux



25
26
27
# File 'lib/gdk/machine.rb', line 25

def self.wsl?
  platform == 'linux' && Etc.uname[:release].include?('microsoft')
end

.x86_64?Boolean

Is the machine running on an x86_64 processor?

Returns:

  • (Boolean)

    whether current CPU is using x86_64 architecture



46
47
48
# File 'lib/gdk/machine.rb', line 46

def self.x86_64?
  architecture == 'x86_64'
end