Class: Ukiryu::Execution::Output
- Inherits:
-
Object
- Object
- Ukiryu::Execution::Output
- Defined in:
- lib/ukiryu/execution/output.rb
Overview
Captured output from command execution
Provides typed access to stdout and stderr with parsing utilities
Instance Attribute Summary collapse
-
#exit_status ⇒ Object
readonly
Returns the value of attribute exit_status.
-
#raw_stderr ⇒ Object
readonly
Returns the value of attribute raw_stderr.
-
#raw_stdout ⇒ Object
readonly
Returns the value of attribute raw_stdout.
Instance Method Summary collapse
-
#failure? ⇒ Boolean
Check if command failed.
-
#initialize(stdout:, stderr:, exit_status:) ⇒ Output
constructor
A new instance of Output.
-
#inspect ⇒ String
Inspect.
-
#stderr ⇒ String
Get stderr as a string (stripped).
-
#stderr_contains?(pattern) ⇒ Boolean
Check if stderr contains a pattern.
-
#stderr_empty? ⇒ Boolean
Check if stderr is empty.
-
#stderr_length ⇒ Integer
Get stderr length.
-
#stderr_lines ⇒ Array<String>
Get stderr lines as an array.
-
#stdout ⇒ String
Get stdout as a string (stripped).
-
#stdout_contains?(pattern) ⇒ Boolean
Check if stdout contains a pattern.
-
#stdout_empty? ⇒ Boolean
Check if stdout is empty.
-
#stdout_length ⇒ Integer
Get stdout length.
-
#stdout_lines ⇒ Array<String>
Get stdout lines as an array.
-
#success? ⇒ Boolean
Check if command succeeded.
-
#to_h ⇒ Hash
Convert to hash.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(stdout:, stderr:, exit_status:) ⇒ Output
Returns a new instance of Output.
11 12 13 14 15 |
# File 'lib/ukiryu/execution/output.rb', line 11 def initialize(stdout:, stderr:, exit_status:) @raw_stdout = stdout @raw_stderr = stderr @exit_status = exit_status end |
Instance Attribute Details
#exit_status ⇒ Object (readonly)
Returns the value of attribute exit_status.
9 10 11 |
# File 'lib/ukiryu/execution/output.rb', line 9 def exit_status @exit_status end |
#raw_stderr ⇒ Object (readonly)
Returns the value of attribute raw_stderr.
9 10 11 |
# File 'lib/ukiryu/execution/output.rb', line 9 def raw_stderr @raw_stderr end |
#raw_stdout ⇒ Object (readonly)
Returns the value of attribute raw_stdout.
9 10 11 |
# File 'lib/ukiryu/execution/output.rb', line 9 def raw_stdout @raw_stdout end |
Instance Method Details
#failure? ⇒ Boolean
Check if command failed
107 108 109 |
# File 'lib/ukiryu/execution/output.rb', line 107 def failure? @exit_status != 0 end |
#inspect ⇒ String
Inspect
139 140 141 |
# File 'lib/ukiryu/execution/output.rb', line 139 def inspect "#<Ukiryu::Execution::Output exit=#{@exit_status} success=#{success?}>" end |
#stderr ⇒ String
Get stderr as a string (stripped)
27 28 29 |
# File 'lib/ukiryu/execution/output.rb', line 27 def stderr @raw_stderr.strip end |
#stderr_contains?(pattern) ⇒ Boolean
Check if stderr contains a pattern
61 62 63 64 65 66 67 |
# File 'lib/ukiryu/execution/output.rb', line 61 def stderr_contains?(pattern) if pattern.is_a?(Regexp) @raw_stderr.match?(pattern) else @raw_stderr.include?(pattern.to_s) end end |
#stderr_empty? ⇒ Boolean
Check if stderr is empty
79 80 81 |
# File 'lib/ukiryu/execution/output.rb', line 79 def stderr_empty? @raw_stderr.strip.empty? end |
#stderr_length ⇒ Integer
Get stderr length
93 94 95 |
# File 'lib/ukiryu/execution/output.rb', line 93 def stderr_length @raw_stderr.length end |
#stderr_lines ⇒ Array<String>
Get stderr lines as an array
41 42 43 |
# File 'lib/ukiryu/execution/output.rb', line 41 def stderr_lines @raw_stderr.split(/\r?\n/) end |
#stdout ⇒ String
Get stdout as a string (stripped)
20 21 22 |
# File 'lib/ukiryu/execution/output.rb', line 20 def stdout @raw_stdout.strip end |
#stdout_contains?(pattern) ⇒ Boolean
Check if stdout contains a pattern
49 50 51 52 53 54 55 |
# File 'lib/ukiryu/execution/output.rb', line 49 def stdout_contains?(pattern) if pattern.is_a?(Regexp) @raw_stdout.match?(pattern) else @raw_stdout.include?(pattern.to_s) end end |
#stdout_empty? ⇒ Boolean
Check if stdout is empty
72 73 74 |
# File 'lib/ukiryu/execution/output.rb', line 72 def stdout_empty? @raw_stdout.strip.empty? end |
#stdout_length ⇒ Integer
Get stdout length
86 87 88 |
# File 'lib/ukiryu/execution/output.rb', line 86 def stdout_length @raw_stdout.length end |
#stdout_lines ⇒ Array<String>
Get stdout lines as an array
34 35 36 |
# File 'lib/ukiryu/execution/output.rb', line 34 def stdout_lines @raw_stdout.split(/\r?\n/) end |
#success? ⇒ Boolean
Check if command succeeded
100 101 102 |
# File 'lib/ukiryu/execution/output.rb', line 100 def success? @exit_status.zero? end |
#to_h ⇒ Hash
Convert to hash
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/ukiryu/execution/output.rb', line 114 def to_h { stdout: @raw_stdout, stderr: @raw_stderr, exit_status: @exit_status, success: success?, stdout_lines: stdout_lines, stderr_lines: stderr_lines } end |
#to_s ⇒ String
String representation
128 129 130 131 132 133 134 |
# File 'lib/ukiryu/execution/output.rb', line 128 def to_s if success? "Success (exit: #{@exit_status}, stdout: #{stdout_length} bytes, stderr: #{stderr_length} bytes)" else "Failed (exit: #{@exit_status}, stdout: #{stdout_length} bytes, stderr: #{stderr_length} bytes)" end end |