Class: Mnenv::PlatformDetector
- Inherits:
-
Object
- Object
- Mnenv::PlatformDetector
- Defined in:
- lib/mnenv/platform_detector.rb
Overview
Centralized platform detection for consistent OS/architecture/variant detection across the codebase. Used by binary installer, repository, and CLI.
Defined Under Namespace
Classes: UnsupportedPlatform
Class Method Summary collapse
-
.arch ⇒ String
Detect the current CPU architecture.
-
.linux? ⇒ Boolean
Check if running on Linux.
-
.macos? ⇒ Boolean
Check if running on macOS.
-
.musl? ⇒ Boolean
Check if running on a musl-based system (Alpine Linux).
-
.os ⇒ String
Detect the current operating system.
-
.platform_candidates ⇒ Array<String>
Get all possible platform strings for binary matching (includes variant-specific and generic versions).
-
.platform_string ⇒ String
Get a human-readable platform string.
-
.to_h ⇒ Hash
Get platform info as a hash.
-
.variant ⇒ String?
Detect libc variant (for Linux).
-
.windows? ⇒ Boolean
Check if running on Windows.
Class Method Details
.arch ⇒ String
Detect the current CPU architecture
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/mnenv/platform_detector.rb', line 28 def arch case RbConfig::CONFIG['host_cpu'] when /arm64|aarch64/ 'arm64' when /x86_64|x64/ 'x86_64' else 'x86_64' # Default fallback end end |
.linux? ⇒ Boolean
Check if running on Linux
70 71 72 |
# File 'lib/mnenv/platform_detector.rb', line 70 def linux? os == 'linux' end |
.macos? ⇒ Boolean
Check if running on macOS
64 65 66 |
# File 'lib/mnenv/platform_detector.rb', line 64 def macos? os == 'darwin' end |
.musl? ⇒ Boolean
Check if running on a musl-based system (Alpine Linux)
49 50 51 52 53 54 |
# File 'lib/mnenv/platform_detector.rb', line 49 def musl? File.exist?('/etc/alpine-release') || File.symlink?('/lib/libc.musl-x86_64.so.1') rescue StandardError false end |
.os ⇒ String
Detect the current operating system
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/mnenv/platform_detector.rb', line 13 def os case RbConfig::CONFIG['host_os'] when /linux/ 'linux' when /darwin/ 'darwin' when /mswin|mingw|cygwin/ 'windows' else raise UnsupportedPlatform, "Unsupported platform: #{RbConfig::CONFIG['host_os']}" end end |
.platform_candidates ⇒ Array<String>
Get all possible platform strings for binary matching (includes variant-specific and generic versions)
96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/mnenv/platform_detector.rb', line 96 def platform_candidates candidates = [] # With variant (if applicable) candidates << "#{os}-#{variant}-#{arch}" if variant # Without variant candidates << "#{os}-#{arch}" candidates end |
.platform_string ⇒ String
Get a human-readable platform string
86 87 88 89 90 91 |
# File 'lib/mnenv/platform_detector.rb', line 86 def platform_string parts = [os] parts << variant if variant parts << arch parts.join('-') end |
.to_h ⇒ Hash
Get platform info as a hash
76 77 78 79 80 81 82 |
# File 'lib/mnenv/platform_detector.rb', line 76 def to_h { os: os, arch: arch, variant: variant } end |
.variant ⇒ String?
Detect libc variant (for Linux)
41 42 43 44 45 |
# File 'lib/mnenv/platform_detector.rb', line 41 def variant return nil unless os == 'linux' 'musl' if musl? end |
.windows? ⇒ Boolean
Check if running on Windows
58 59 60 |
# File 'lib/mnenv/platform_detector.rb', line 58 def windows? os == 'windows' end |