Class: Ukiryu::Runtime
- Inherits:
-
Object
- Object
- Ukiryu::Runtime
- Includes:
- Singleton
- Defined in:
- lib/ukiryu/runtime.rb
Overview
Runtime singleton for centralized platform and shell detection.
This class provides a single source of truth for platform and shell detection across the entire application, eliminating redundant detection calls and ensuring consistency.
Instance Method Summary collapse
-
#initialize ⇒ Runtime
constructor
Initialize the runtime with cached values.
-
#linux? ⇒ Boolean
Check if running on Linux.
-
#lock! ⇒ Object
Lock the runtime to prevent further changes.
-
#macos? ⇒ Boolean
Check if running on macOS.
-
#on_platform?(plat) ⇒ Boolean
Check if running on a specific platform.
-
#platform ⇒ Symbol
Get the current platform (cached).
-
#platform=(value) ⇒ Object
Manually set the platform (for testing).
-
#platform_class ⇒ Class
Get the platform class for the current platform.
-
#reset! ⇒ Object
private
Reset the runtime cache (for testing).
-
#shell ⇒ Symbol
Get the current shell (cached).
-
#shell=(value) ⇒ Object
Manually set the shell (for testing).
-
#shell_class ⇒ Class
Get the shell class for the current shell.
-
#unix_shell? ⇒ Boolean
Check if using a Unix-like shell.
-
#using_shell?(sh) ⇒ Boolean
Check if using a specific shell.
-
#windows? ⇒ Boolean
Check if running on Windows.
-
#windows_shell? ⇒ Boolean
Check if using a Windows shell.
Constructor Details
#initialize ⇒ Runtime
Initialize the runtime with cached values
19 20 21 22 23 24 25 |
# File 'lib/ukiryu/runtime.rb', line 19 def initialize @platform = nil @shell = nil @platform_cached = false @shell_cached = false @locked = false end |
Instance Method Details
#linux? ⇒ Boolean
Check if running on Linux
148 149 150 |
# File 'lib/ukiryu/runtime.rb', line 148 def linux? on_platform?(:linux) end |
#lock! ⇒ Object
Lock the runtime to prevent further changes
This should be called after initial configuration is complete.
86 87 88 |
# File 'lib/ukiryu/runtime.rb', line 86 def lock! @locked = true end |
#macos? ⇒ Boolean
Check if running on macOS
141 142 143 |
# File 'lib/ukiryu/runtime.rb', line 141 def macos? on_platform?(:macos) end |
#on_platform?(plat) ⇒ Boolean
Check if running on a specific platform
119 120 121 |
# File 'lib/ukiryu/runtime.rb', line 119 def on_platform?(plat) platform == plat.to_sym end |
#platform ⇒ Symbol
Get the current platform (cached)
30 31 32 33 34 35 36 |
# File 'lib/ukiryu/runtime.rb', line 30 def platform return @platform if @platform_cached @platform = Ukiryu::Platform.detect @platform_cached = true @platform end |
#platform=(value) ⇒ Object
Manually set the platform (for testing)
66 67 68 69 70 71 |
# File 'lib/ukiryu/runtime.rb', line 66 def platform=(value) raise 'Runtime is locked' if @locked @platform = value&.to_sym @platform_cached = true end |
#platform_class ⇒ Class
Get the platform class for the current platform
104 105 106 |
# File 'lib/ukiryu/runtime.rb', line 104 def platform_class Ukiryu::Platform.class_for(platform) end |
#reset! ⇒ 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 the runtime cache (for testing)
93 94 95 96 97 98 99 |
# File 'lib/ukiryu/runtime.rb', line 93 def reset! @platform = nil @shell = nil @platform_cached = false @shell_cached = false @locked = false end |
#shell ⇒ Symbol
Get the current shell (cached)
Priority:
-
Explicitly set shell (via shell=)
-
Config.shell (from –shell CLI option, UKIRYU_SHELL env, or programmatic config)
-
Auto-detected shell
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ukiryu/runtime.rb', line 46 def shell return @shell if @shell_cached # Check for explicit override override = shell_override if override @shell = override @shell_cached = true return @shell end # Auto-detect @shell = Ukiryu::Shell.detect @shell_cached = true @shell end |
#shell=(value) ⇒ Object
Manually set the shell (for testing)
76 77 78 79 80 81 |
# File 'lib/ukiryu/runtime.rb', line 76 def shell=(value) raise 'Runtime is locked' if @locked @shell = value&.to_sym @shell_cached = true end |
#shell_class ⇒ Class
Get the shell class for the current shell
111 112 113 |
# File 'lib/ukiryu/runtime.rb', line 111 def shell_class Ukiryu::Shell.class_for(shell) end |
#unix_shell? ⇒ Boolean
Check if using a Unix-like shell
155 156 157 |
# File 'lib/ukiryu/runtime.rb', line 155 def unix_shell? %i[bash zsh fish sh].include?(shell) end |
#using_shell?(sh) ⇒ Boolean
Check if using a specific shell
127 128 129 |
# File 'lib/ukiryu/runtime.rb', line 127 def using_shell?(sh) shell == sh.to_sym end |
#windows? ⇒ Boolean
Check if running on Windows
134 135 136 |
# File 'lib/ukiryu/runtime.rb', line 134 def windows? on_platform?(:windows) end |
#windows_shell? ⇒ Boolean
Check if using a Windows shell
162 163 164 |
# File 'lib/ukiryu/runtime.rb', line 162 def windows_shell? %i[powershell cmd].include?(shell) end |