Class: Wip::Environment
- Inherits:
-
Object
- Object
- Wip::Environment
- Defined in:
- lib/wip/environment.rb
Overview
Detects WSL2, Windows interop, and architecture facts about the host.
Instance Method Summary collapse
- #architecture ⇒ Object
-
#initialize(stdin: $stdin, stdout: $stdout) ⇒ Environment
constructor
A new instance of Environment.
- #interactive? ⇒ Boolean
- #windows? ⇒ Boolean
- #windows_interop? ⇒ Boolean
- #wsl2? ⇒ Boolean
Constructor Details
#initialize(stdin: $stdin, stdout: $stdout) ⇒ Environment
Returns a new instance of Environment.
8 9 10 11 |
# File 'lib/wip/environment.rb', line 8 def initialize(stdin: $stdin, stdout: $stdout) @stdin = stdin @stdout = stdout end |
Instance Method Details
#architecture ⇒ Object
26 27 28 29 30 |
# File 'lib/wip/environment.rb', line 26 def architecture machine = RbConfig::CONFIG['host_cpu'] { 'x86_64' => 'linux/amd64', 'x64' => 'linux/amd64', 'aarch64' => 'linux/arm64', 'arm64' => 'linux/arm64' } .fetch(machine, "linux/#{machine}") end |
#interactive? ⇒ Boolean
24 |
# File 'lib/wip/environment.rb', line 24 def interactive? = @stdin.tty? && @stdout.tty? |
#windows? ⇒ Boolean
13 |
# File 'lib/wip/environment.rb', line 13 def windows? = Gem.win_platform? |
#windows_interop? ⇒ Boolean
23 |
# File 'lib/wip/environment.rb', line 23 def windows_interop? = File.executable?('/proc/sys/fs/binfmt_misc/WSLInterop') || ENV.key?('WSL_INTEROP') |
#wsl2? ⇒ Boolean
15 16 17 18 19 20 21 |
# File 'lib/wip/environment.rb', line 15 def wsl2? return wsl2_backend_available? if windows? File.read('/proc/version').match?(/microsoft.*WSL2/i) rescue Errno::ENOENT false end |