Class: Ukiryu::Execution::Result
- Inherits:
-
Object
- Object
- Ukiryu::Execution::Result
- Defined in:
- lib/ukiryu/execution/result.rb
Overview
Result class for command execution
Provides a rich, object-oriented interface to command execution results. Composes CommandInfo, Output, and ExecutionMetadata for a fully OOP design.
Instance Attribute Summary collapse
-
#command_info ⇒ Object
readonly
Returns the value of attribute command_info.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#output ⇒ String
readonly
Get stdout as a stripped string.
Instance Method Summary collapse
-
#command ⇒ String
Get the full command string.
-
#duration ⇒ Float?
Get execution duration.
-
#error_output ⇒ String
Get stderr as a stripped string.
-
#executable ⇒ String
Get the executable.
-
#executable_name ⇒ String
Get the executable name only.
-
#execution_time ⇒ Float?
Get execution duration (alias).
-
#exit_status ⇒ Integer
Get the exit code (alias for status).
-
#failure? ⇒ Boolean
Check if the command failed.
-
#finished_at ⇒ Time
Get finish time.
-
#initialize(command_info:, output:, metadata:) ⇒ Result
constructor
A new instance of Result.
-
#inspect ⇒ String
Inspect.
-
#started_at ⇒ Time
Get start time.
-
#status ⇒ Integer
(also: #exit_code)
Get exit status code.
-
#stderr ⇒ String
Get raw stderr.
-
#stderr_contains?(pattern) ⇒ Boolean
Check if stderr contains a pattern.
-
#stderr_lines ⇒ Array<String>
Get stderr lines.
-
#stdout ⇒ String
Get raw stdout.
-
#stdout_contains?(pattern) ⇒ Boolean
Check if stdout contains a pattern.
-
#stdout_lines ⇒ Array<String>
Get stdout lines.
-
#success? ⇒ Boolean
Check if the command succeeded.
-
#to_h ⇒ Hash
Get a hash representation of the result.
-
#to_json(*args) ⇒ String
Get a JSON representation of the result.
-
#to_s ⇒ String
String representation of the result.
Constructor Details
#initialize(command_info:, output:, metadata:) ⇒ Result
Returns a new instance of Result.
12 13 14 15 16 |
# File 'lib/ukiryu/execution/result.rb', line 12 def initialize(command_info:, output:, metadata:) @command_info = command_info @output = output @metadata = end |
Instance Attribute Details
#command_info ⇒ Object (readonly)
Returns the value of attribute command_info.
10 11 12 |
# File 'lib/ukiryu/execution/result.rb', line 10 def command_info @command_info end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
10 11 12 |
# File 'lib/ukiryu/execution/result.rb', line 10 def @metadata end |
#output ⇒ String (readonly)
Get stdout as a stripped string
113 114 115 |
# File 'lib/ukiryu/execution/result.rb', line 113 def output @output end |
Instance Method Details
#command ⇒ String
Get the full command string
21 22 23 |
# File 'lib/ukiryu/execution/result.rb', line 21 def command @command_info.full_command end |
#duration ⇒ Float?
Get execution duration
85 86 87 |
# File 'lib/ukiryu/execution/result.rb', line 85 def duration @metadata.duration end |
#error_output ⇒ String
Get stderr as a stripped string
120 121 122 |
# File 'lib/ukiryu/execution/result.rb', line 120 def error_output @output.stderr end |
#executable ⇒ String
Get the executable
28 29 30 |
# File 'lib/ukiryu/execution/result.rb', line 28 def executable @command_info.executable end |
#executable_name ⇒ String
Get the executable name only
35 36 37 |
# File 'lib/ukiryu/execution/result.rb', line 35 def executable_name @command_info.executable_name end |
#execution_time ⇒ Float?
Get execution duration (alias)
92 93 94 |
# File 'lib/ukiryu/execution/result.rb', line 92 def execution_time @metadata.duration_seconds end |
#exit_status ⇒ Integer
Get the exit code (alias for status)
64 65 66 |
# File 'lib/ukiryu/execution/result.rb', line 64 def exit_status @output.exit_status end |
#failure? ⇒ Boolean
Check if the command failed
106 107 108 |
# File 'lib/ukiryu/execution/result.rb', line 106 def failure? @output.failure? end |
#finished_at ⇒ Time
Get finish time
78 79 80 |
# File 'lib/ukiryu/execution/result.rb', line 78 def finished_at @metadata.finished_at end |
#inspect ⇒ String
Inspect
189 190 191 |
# File 'lib/ukiryu/execution/result.rb', line 189 def inspect "#<Ukiryu::Execution::Result #{self}>" end |
#started_at ⇒ Time
Get start time
71 72 73 |
# File 'lib/ukiryu/execution/result.rb', line 71 def started_at @metadata.started_at end |
#status ⇒ Integer Also known as: exit_code
Get exit status code
56 57 58 |
# File 'lib/ukiryu/execution/result.rb', line 56 def status @output.exit_status end |
#stderr ⇒ String
Get raw stderr
49 50 51 |
# File 'lib/ukiryu/execution/result.rb', line 49 def stderr @output.raw_stderr end |
#stderr_contains?(pattern) ⇒ Boolean
Check if stderr contains a pattern
150 151 152 |
# File 'lib/ukiryu/execution/result.rb', line 150 def stderr_contains?(pattern) @output.stderr_contains?(pattern) end |
#stderr_lines ⇒ Array<String>
Get stderr lines
134 135 136 |
# File 'lib/ukiryu/execution/result.rb', line 134 def stderr_lines @output.stderr_lines end |
#stdout ⇒ String
Get raw stdout
42 43 44 |
# File 'lib/ukiryu/execution/result.rb', line 42 def stdout @output.raw_stdout end |
#stdout_contains?(pattern) ⇒ Boolean
Check if stdout contains a pattern
142 143 144 |
# File 'lib/ukiryu/execution/result.rb', line 142 def stdout_contains?(pattern) @output.stdout_contains?(pattern) end |
#stdout_lines ⇒ Array<String>
Get stdout lines
127 128 129 |
# File 'lib/ukiryu/execution/result.rb', line 127 def stdout_lines @output.stdout_lines end |
#success? ⇒ Boolean
Check if the command succeeded
99 100 101 |
# File 'lib/ukiryu/execution/result.rb', line 99 def success? @output.success? end |
#to_h ⇒ Hash
Get a hash representation of the result
157 158 159 160 161 162 163 164 165 |
# File 'lib/ukiryu/execution/result.rb', line 157 def to_h { command: @command_info.to_h, output: @output.to_h, metadata: @metadata.to_h, success: success?, status: status } end |
#to_json(*args) ⇒ String
Get a JSON representation of the result
170 171 172 173 |
# File 'lib/ukiryu/execution/result.rb', line 170 def to_json(*args) require 'json' to_h.to_json(*args) end |
#to_s ⇒ String
String representation of the result
178 179 180 181 182 183 184 |
# File 'lib/ukiryu/execution/result.rb', line 178 def to_s if success? "Success: #{command} (#{.formatted_duration})" else "Failed: #{command} (exit: #{status}, #{.formatted_duration})" end end |