Module: Cinnabar::Utils::OS
- Defined in:
- lib/cinnabar/utils.rb
Class Method Summary collapse
-
.linux?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on Linux.
-
.macOS?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on macOS (Darwin).
-
.windows?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on Windows (including MSYS/MinGW/Cygwin).
-
.wsl?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL (Windows Subsystem for Linux).
-
.wsl_1?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL 1.
-
.wsl_2?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL 2.
Class Method Details
.linux?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on Linux.
43 44 45 |
# File 'lib/cinnabar/utils.rb', line 43 def linux?(host_os = RUBY_PLATFORM) host_os.match?(/linux/i) end |
.macOS?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on macOS (Darwin).
Ruby convention prefers macos? over macOS?, but we provide both.
35 36 37 |
# File 'lib/cinnabar/utils.rb', line 35 def macOS?(host_os = RUBY_PLATFORM) # rubocop:disable Naming/MethodName host_os.match?(/darwin/i) end |
.windows?(host_os = RUBY_PLATFORM) ⇒ Boolean
Returns true if running on Windows (including MSYS/MinGW/Cygwin).
22 23 24 |
# File 'lib/cinnabar/utils.rb', line 22 def windows?(host_os = RUBY_PLATFORM) host_os.match?(/bccwin|cygwin|djgpp|mingw|mswin|wince/i) end |
.wsl?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL (Windows Subsystem for Linux).
66 67 68 69 70 71 |
# File 'lib/cinnabar/utils.rb', line 66 def wsl?(proc_version = nil) proc_version ||= File.read('/proc/version') proc_version.match?(/(M|m)icrosoft/) rescue StandardError false end |
.wsl_1?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL 1
74 75 76 77 78 79 80 |
# File 'lib/cinnabar/utils.rb', line 74 def wsl_1?(proc_version = nil) # wsl 1: Linux version 4.4.0-26100-Microsoft (Microsoft@Microsoft.com) (gcc version 5.4.0 (GCC) ) #7309-Microsoft Fri Jan 01 08:00:00 PST 2016 # rubocop:disable Layout/LineLength proc_version ||= File.read('/proc/version') proc_version.include?('Microsoft') rescue StandardError false end |
.wsl_2?(proc_version = nil) ⇒ Boolean
Returns true if running under WSL 2
56 57 58 59 60 61 62 63 |
# File 'lib/cinnabar/utils.rb', line 56 def wsl_2?(proc_version = nil) proc_version ||= File.read('/proc/version') # proc_version.match?(/(?=.*microsoft)(?=.*-WSL)/) proc_version.include?('microsoft') && proc_version.include?('-WSL') rescue StandardError false end |