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

Class Method Details

.detectSymbol

Detect the current platform

Returns:

  • (Symbol)

    :windows, :macos, or :linux

Raises:

  • (UnsupportedPlatformError)

    if platform cannot be determined



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_pathsArray<String>

Get the PATH environment variable as an array Handles different PATH separators on Windows (;) vs Unix (:)

Returns:

  • (Array<String>)

    array of directory paths



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

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


56
57
58
# File 'lib/ukiryu/platform.rb', line 56

def macos?
  RbConfig::CONFIG['host_os'] =~ /darwin|mac os/i
end

.reset_cacheObject

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)

Returns:

  • (Boolean)


70
71
72
# File 'lib/ukiryu/platform.rb', line 70

def unix?
  macos? || linux?
end

.windows?Boolean

Check if running on Windows

Returns:

  • (Boolean)


49
50
51
# File 'lib/ukiryu/platform.rb', line 49

def windows?
  Gem.win_platform? || RbConfig::CONFIG['host_os'] =~ /mswin|mingw|windows/i
end