Module: Ukiryu::Platform
- Defined in:
- lib/ukiryu/platform.rb
Overview
Platform detection module
Provides explicit platform detection with clear error messages. No automatic fallbacks - if platform cannot be determined, raises an error.
Class Method Summary collapse
-
.detect ⇒ Symbol
Detect the current platform.
-
.executable_search_paths ⇒ Array<String>
Get the PATH environment variable as an array Handles different PATH separators on Windows (;) vs Unix (:).
-
.linux? ⇒ Boolean
Check if running on Linux.
-
.macos? ⇒ Boolean
Check if running on macOS.
-
.reset_cache ⇒ Object
private
Reset cached paths (primarily for testing).
-
.unix? ⇒ Boolean
Check if running on a Unix-like system (macOS or Linux).
-
.windows? ⇒ Boolean
Check if running on Windows.
Class Method Details
.detect ⇒ Symbol
Detect the current platform
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ukiryu/platform.rb', line 14 def detect if windows? :windows elsif macos? :macos elsif linux? :linux else # Try to determine from RbConfig host_os = RbConfig::CONFIG['host_os'] case host_os when /mswin|mingw|windows/i :windows when /darwin|mac os/i :macos when /linux/i :linux else raise Ukiryu::Errors::UnsupportedPlatformError, <<~ERROR Unable to detect platform. Host OS: #{host_os} Supported platforms: Windows, macOS, Linux Please configure platform explicitly: Ukiryu.configure do |config| config.platform = :linux # or :macos, :windows end ERROR end end end |
.executable_search_paths ⇒ Array<String>
Get the PATH environment variable as an array Handles different PATH separators on Windows (;) vs Unix (:)
78 79 80 81 82 83 |
# File 'lib/ukiryu/platform.rb', line 78 def executable_search_paths @executable_search_paths ||= begin path_sep = windows? ? ';' : ':' (ENV['PATH'] || '').split(path_sep) end end |
.linux? ⇒ Boolean
Check if running on Linux
63 64 65 |
# File 'lib/ukiryu/platform.rb', line 63 def linux? RbConfig::CONFIG['host_os'] =~ /linux/i end |
.macos? ⇒ Boolean
Check if running on macOS
56 57 58 |
# File 'lib/ukiryu/platform.rb', line 56 def macos? RbConfig::CONFIG['host_os'] =~ /darwin|mac os/i end |
.reset_cache ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reset cached paths (primarily for testing)
88 89 90 |
# File 'lib/ukiryu/platform.rb', line 88 def reset_cache @executable_search_paths = nil end |
.unix? ⇒ Boolean
Check if running on a Unix-like system (macOS or Linux)
70 71 72 |
# File 'lib/ukiryu/platform.rb', line 70 def unix? macos? || linux? end |
.windows? ⇒ Boolean
Check if running on Windows
49 50 51 |
# File 'lib/ukiryu/platform.rb', line 49 def windows? Gem.win_platform? || RbConfig::CONFIG['host_os'] =~ /mswin|mingw|windows/i end |