Class: Ukiryu::ExecutionContext
- Inherits:
-
Object
- Object
- Ukiryu::ExecutionContext
- Defined in:
- lib/ukiryu/execution_context.rb,
lib/ukiryu/execution_context.rb
Overview
Execution context for dependency injection and execution-scoped configuration
Provides a non-singleton alternative to Runtime.instance for better testability. Wraps runtime configuration and execution-specific options in a single object.
Defined Under Namespace
Classes: ThreadLocal
Instance Attribute Summary collapse
-
#debug ⇒ Boolean
readonly
Debug mode enabled.
-
#metrics ⇒ Boolean
readonly
Metrics collection enabled.
-
#options ⇒ Hash
readonly
User-defined options hash.
-
#platform ⇒ Symbol
readonly
Platform (:macos, :linux, :windows).
-
#register_path ⇒ String?
readonly
Register path for tool profiles.
-
#shell ⇒ Symbol
readonly
Shell (:bash, :zsh, :fish, :powershell, :cmd).
-
#timeout ⇒ Integer?
readonly
Execution timeout in seconds.
Class Method Summary collapse
-
.current ⇒ ExecutionContext
Get the current execution context.
-
.current=(context) ⇒ void
Set the current execution context.
-
.from_runtime ⇒ ExecutionContext
Create a context from the global Runtime.
-
.reset_current! ⇒ Object
private
Reset the current context (mainly for testing).
-
.with_context(context) { ... } ⇒ Object
Execute a block with a temporary context.
Instance Method Summary collapse
-
#initialize(platform: nil, shell: nil, register_path: nil, timeout: nil, debug: false, metrics: false, options: {}) ⇒ ExecutionContext
constructor
Create a new execution context.
-
#inspect ⇒ String
Inspect.
-
#linux? ⇒ Boolean
Check if running on Linux.
-
#macos? ⇒ Boolean
Check if running on macOS.
-
#merge(changes) ⇒ ExecutionContext
Create a new context with merged options.
-
#on_platform?(plat) ⇒ Boolean
Check if running on a specific platform.
-
#shell_class ⇒ Class
Get the shell class for this context.
-
#to_s ⇒ String
String representation.
-
#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(platform: nil, shell: nil, register_path: nil, timeout: nil, debug: false, metrics: false, options: {}) ⇒ ExecutionContext
Create a new execution context
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ukiryu/execution_context.rb', line 144 def initialize(platform: nil, shell: nil, register_path: nil, timeout: nil, debug: false, metrics: false, options: {}) @platform = platform @shell = shell @register_path = register_path @timeout = timeout @debug = debug @metrics = metrics @options = end |
Instance Attribute Details
#debug ⇒ Boolean (readonly)
Debug mode enabled
123 124 125 |
# File 'lib/ukiryu/execution_context.rb', line 123 def debug @debug end |
#metrics ⇒ Boolean (readonly)
Metrics collection enabled
128 129 130 |
# File 'lib/ukiryu/execution_context.rb', line 128 def metrics @metrics end |
#options ⇒ Hash (readonly)
User-defined options hash
133 134 135 |
# File 'lib/ukiryu/execution_context.rb', line 133 def @options end |
#platform ⇒ Symbol (readonly)
Platform (:macos, :linux, :windows)
103 104 105 |
# File 'lib/ukiryu/execution_context.rb', line 103 def platform @platform end |
#register_path ⇒ String? (readonly)
Register path for tool profiles
113 114 115 |
# File 'lib/ukiryu/execution_context.rb', line 113 def register_path @register_path end |
#shell ⇒ Symbol (readonly)
Shell (:bash, :zsh, :fish, :powershell, :cmd)
108 109 110 |
# File 'lib/ukiryu/execution_context.rb', line 108 def shell @shell end |
#timeout ⇒ Integer? (readonly)
Execution timeout in seconds
118 119 120 |
# File 'lib/ukiryu/execution_context.rb', line 118 def timeout @timeout end |
Class Method Details
.current ⇒ ExecutionContext
Get the current execution context
Creates a new context from the global Runtime if none is set.
52 53 54 |
# File 'lib/ukiryu/execution_context.rb', line 52 def current @current_context.value ||= from_runtime end |
.current=(context) ⇒ void
This method returns an undefined value.
Set the current execution context
60 61 62 |
# File 'lib/ukiryu/execution_context.rb', line 60 def current=(context) @current_context.value = context end |
.from_runtime ⇒ ExecutionContext
Create a context from the global Runtime
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ukiryu/execution_context.rb', line 80 def from_runtime runtime = Ukiryu::Runtime.instance new( platform: runtime.platform, shell: runtime.shell, register_path: Ukiryu::Register.default_register_path, timeout: Ukiryu::Config.timeout, debug: Ukiryu::Config.debug, metrics: Ukiryu::Config.metrics ) end |
.reset_current! ⇒ 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 current context (mainly for testing)
95 96 97 |
# File 'lib/ukiryu/execution_context.rb', line 95 def reset_current! @current_context.value = nil end |
.with_context(context) { ... } ⇒ Object
Execute a block with a temporary context
69 70 71 72 73 74 75 |
# File 'lib/ukiryu/execution_context.rb', line 69 def with_context(context) old_context = @current_context.value @current_context.value = context yield ensure @current_context.value = old_context end |
Instance Method Details
#inspect ⇒ String
Inspect
244 245 246 |
# File 'lib/ukiryu/execution_context.rb', line 244 def inspect "#<#{self.class} #{self}>" end |
#linux? ⇒ Boolean
Check if running on Linux
200 201 202 |
# File 'lib/ukiryu/execution_context.rb', line 200 def linux? on_platform?(:linux) end |
#macos? ⇒ Boolean
Check if running on macOS
193 194 195 |
# File 'lib/ukiryu/execution_context.rb', line 193 def macos? on_platform?(:macos) end |
#merge(changes) ⇒ ExecutionContext
Create a new context with merged options
222 223 224 225 226 227 228 229 230 231 232 |
# File 'lib/ukiryu/execution_context.rb', line 222 def merge(changes) self.class.new( platform: changes.fetch(:platform, @platform), shell: changes.fetch(:shell, @shell), register_path: changes.fetch(:register_path, @register_path), timeout: changes.fetch(:timeout, @timeout), debug: changes.fetch(:debug, @debug), metrics: changes.fetch(:metrics, @metrics), options: @options.merge(changes.fetch(:options, {})) ) end |
#on_platform?(plat) ⇒ Boolean
Check if running on a specific platform
171 172 173 |
# File 'lib/ukiryu/execution_context.rb', line 171 def on_platform?(plat) @platform == plat.to_sym end |
#shell_class ⇒ Class
Get the shell class for this context
163 164 165 |
# File 'lib/ukiryu/execution_context.rb', line 163 def shell_class Ukiryu::Shell.class_for(@shell) end |
#to_s ⇒ String
String representation
237 238 239 |
# File 'lib/ukiryu/execution_context.rb', line 237 def to_s "ExecutionContext(platform=#{@platform}, shell=#{@shell}, register=#{@register_path})" end |
#unix_shell? ⇒ Boolean
Check if using a Unix-like shell
207 208 209 |
# File 'lib/ukiryu/execution_context.rb', line 207 def unix_shell? %i[bash zsh fish sh].include?(@shell) end |
#using_shell?(sh) ⇒ Boolean
Check if using a specific shell
179 180 181 |
# File 'lib/ukiryu/execution_context.rb', line 179 def using_shell?(sh) @shell == sh.to_sym end |
#windows? ⇒ Boolean
Check if running on Windows
186 187 188 |
# File 'lib/ukiryu/execution_context.rb', line 186 def windows? on_platform?(:windows) end |
#windows_shell? ⇒ Boolean
Check if using a Windows shell
214 215 216 |
# File 'lib/ukiryu/execution_context.rb', line 214 def windows_shell? %i[powershell cmd].include?(@shell) end |