Class: Ukiryu::Response::Base Abstract
- Inherits:
-
Object
- Object
- Ukiryu::Response::Base
- Defined in:
- lib/ukiryu/response/base.rb
Overview
Abstract base class for all response classes
This class wraps the raw Executor::Result object and provides a structured interface for accessing command execution results.
Instance Method Summary collapse
-
#arguments ⇒ Array<String>
Get the command arguments.
-
#command ⇒ String
Get the command that was executed.
-
#duration ⇒ Float
Get the execution duration.
-
#executable ⇒ String
Get the executable path.
-
#exit_code ⇒ Integer
Get the exit code.
-
#exit_code_meaning ⇒ String?
Get the exit code meaning (symbol).
-
#finished_at ⇒ Time
Get the end time.
-
#format_meaning ⇒ String
Format exit code meaning.
-
#formatted_duration ⇒ String
Get the formatted duration string.
-
#initialize(result) ⇒ Base
constructor
Create a new response.
-
#inspect ⇒ String
Inspect representation.
-
#raw_result ⇒ Executor::Result
Get the raw result object.
-
#shell ⇒ Symbol
Get the shell type used.
-
#started_at ⇒ Time
Get the start time.
-
#stderr ⇒ String
Get the standard error.
-
#stderr_lines ⇒ Array<String>
Get stderr as lines.
-
#stdout ⇒ String
Get the standard output.
-
#stdout_lines ⇒ Array<String>
Get stdout as lines.
-
#success? ⇒ Boolean
Check if the command was successful.
-
#timed_out? ⇒ Boolean
Check if the command timed out.
-
#to_h ⇒ Hash
(also: #to_hash)
Convert to hash representation.
-
#to_s ⇒ String
String representation.
Constructor Details
#initialize(result) ⇒ Base
Create a new response
15 16 17 |
# File 'lib/ukiryu/response/base.rb', line 15 def initialize(result) @result = result end |
Instance Method Details
#arguments ⇒ Array<String>
Get the command arguments
108 109 110 |
# File 'lib/ukiryu/response/base.rb', line 108 def arguments @result.command_info.arguments end |
#command ⇒ String
Get the command that was executed
94 95 96 |
# File 'lib/ukiryu/response/base.rb', line 94 def command @result.command_info.full_command end |
#duration ⇒ Float
Get the execution duration
122 123 124 |
# File 'lib/ukiryu/response/base.rb', line 122 def duration @result..duration end |
#executable ⇒ String
Get the executable path
101 102 103 |
# File 'lib/ukiryu/response/base.rb', line 101 def executable @result.command_info.executable end |
#exit_code ⇒ Integer
Get the exit code
29 30 31 |
# File 'lib/ukiryu/response/base.rb', line 29 def exit_code @result.status end |
#exit_code_meaning ⇒ String?
Get the exit code meaning (symbol)
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/ukiryu/response/base.rb', line 36 def exit_code_meaning tool_name = @result.command_info.tool_name command_name = @result.command_info.command_name return nil unless tool_name && command_name # Look up the tool by name tool = Ukiryu::Tool.find_by(tool_name.to_sym) return nil unless tool # Get exit codes from the tool's profile profile = tool.profile return nil unless profile command_profile = profile.compatible_profile return nil unless command_profile # First, try to get exit codes from the specific command command = command_profile.command(command_name.to_s) exit_codes = command&.exit_codes # Fall back to profile-level exit codes if command doesn't define its own exit_codes ||= command_profile.exit_codes return nil unless exit_codes exit_codes.meaning(@result.status) end |
#finished_at ⇒ Time
Get the end time
143 144 145 |
# File 'lib/ukiryu/response/base.rb', line 143 def finished_at @result..finished_at end |
#format_meaning ⇒ String
Format exit code meaning
201 202 203 204 205 206 |
# File 'lib/ukiryu/response/base.rb', line 201 def format_meaning meaning = exit_code_meaning return '' unless meaning ": #{meaning}" end |
#formatted_duration ⇒ String
Get the formatted duration string
129 130 131 |
# File 'lib/ukiryu/response/base.rb', line 129 def formatted_duration @result..formatted_duration end |
#inspect ⇒ String
Inspect representation
211 212 213 |
# File 'lib/ukiryu/response/base.rb', line 211 def inspect "#<#{self.class.name} success=#{success?} exit_code=#{exit_code} duration=#{formatted_duration}>" end |
#raw_result ⇒ Executor::Result
Get the raw result object
157 158 159 |
# File 'lib/ukiryu/response/base.rb', line 157 def raw_result @result end |
#shell ⇒ Symbol
Get the shell type used
115 116 117 |
# File 'lib/ukiryu/response/base.rb', line 115 def shell @result.command_info.shell end |
#started_at ⇒ Time
Get the start time
136 137 138 |
# File 'lib/ukiryu/response/base.rb', line 136 def started_at @result..started_at end |
#stderr ⇒ String
Get the standard error
73 74 75 |
# File 'lib/ukiryu/response/base.rb', line 73 def stderr @result.error_output end |
#stderr_lines ⇒ Array<String>
Get stderr as lines
87 88 89 |
# File 'lib/ukiryu/response/base.rb', line 87 def stderr_lines @result.stderr_lines end |
#stdout ⇒ String
Get the standard output
66 67 68 |
# File 'lib/ukiryu/response/base.rb', line 66 def stdout @result.output end |
#stdout_lines ⇒ Array<String>
Get stdout as lines
80 81 82 |
# File 'lib/ukiryu/response/base.rb', line 80 def stdout_lines @result.stdout_lines end |
#success? ⇒ Boolean
Check if the command was successful
22 23 24 |
# File 'lib/ukiryu/response/base.rb', line 22 def success? @result.status.zero? end |
#timed_out? ⇒ Boolean
Check if the command timed out
150 151 152 |
# File 'lib/ukiryu/response/base.rb', line 150 def timed_out? @result.timeout_exceeded? end |
#to_h ⇒ Hash Also known as: to_hash
Convert to hash representation
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'lib/ukiryu/response/base.rb', line 164 def to_h hash = { success: success?, exit_code: exit_code, stdout: stdout, stderr: stderr, command: command, executable: executable, arguments: arguments, shell: shell, duration: duration, started_at: started_at.iso8601, finished_at: finished_at.iso8601 } # Add exit code meaning if available meaning = exit_code_meaning hash[:exit_code_meaning] = meaning if meaning hash end |
#to_s ⇒ String
String representation
190 191 192 193 194 195 196 |
# File 'lib/ukiryu/response/base.rb', line 190 def to_s if success? "Success (exit #{exit_code}#{format_meaning}, #{formatted_duration})" else "Failed (exit #{exit_code}#{format_meaning}, #{formatted_duration})" end end |