Class: Ukiryu::Response::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/ukiryu/response/base.rb

Overview

This class is abstract.

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

Constructor Details

#initialize(result) ⇒ Base

Create a new response

Parameters:

  • result (Executor::Result)

    the raw execution result



15
16
17
# File 'lib/ukiryu/response/base.rb', line 15

def initialize(result)
  @result = result
end

Instance Method Details

#argumentsArray<String>

Get the command arguments

Returns:

  • (Array<String>)

    the arguments passed to the command



108
109
110
# File 'lib/ukiryu/response/base.rb', line 108

def arguments
  @result.command_info.arguments
end

#commandString

Get the command that was executed

Returns:

  • (String)

    the full command string



94
95
96
# File 'lib/ukiryu/response/base.rb', line 94

def command
  @result.command_info.full_command
end

#durationFloat

Get the execution duration

Returns:

  • (Float)

    duration in seconds



122
123
124
# File 'lib/ukiryu/response/base.rb', line 122

def duration
  @result..duration
end

#executableString

Get the executable path

Returns:

  • (String)

    the executable that was run



101
102
103
# File 'lib/ukiryu/response/base.rb', line 101

def executable
  @result.command_info.executable
end

#exit_codeInteger

Get the exit code

Returns:

  • (Integer)

    the exit code



29
30
31
# File 'lib/ukiryu/response/base.rb', line 29

def exit_code
  @result.status
end

#exit_code_meaningString?

Get the exit code meaning (symbol)

Returns:

  • (String, nil)

    the exit code meaning (e.g., “merge_conflict”) or nil if not defined



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_atTime

Get the end time

Returns:

  • (Time)

    when the command finished



143
144
145
# File 'lib/ukiryu/response/base.rb', line 143

def finished_at
  @result..finished_at
end

#format_meaningString

Format exit code meaning

Returns:

  • (String)

    formatted meaning (e.g., “: merge_conflict”)



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_durationString

Get the formatted duration string

Returns:

  • (String)

    human-readable duration (e.g., “1.2s”, “450ms”)



129
130
131
# File 'lib/ukiryu/response/base.rb', line 129

def formatted_duration
  @result..formatted_duration
end

#inspectString

Inspect representation

Returns:

  • (String)

    detailed inspection string



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_resultExecutor::Result

Get the raw result object

Returns:

  • (Executor::Result)

    the raw execution result



157
158
159
# File 'lib/ukiryu/response/base.rb', line 157

def raw_result
  @result
end

#shellSymbol

Get the shell type used

Returns:

  • (Symbol)

    the shell type



115
116
117
# File 'lib/ukiryu/response/base.rb', line 115

def shell
  @result.command_info.shell
end

#started_atTime

Get the start time

Returns:

  • (Time)

    when the command started



136
137
138
# File 'lib/ukiryu/response/base.rb', line 136

def started_at
  @result..started_at
end

#stderrString

Get the standard error

Returns:

  • (String)

    the stderr content



73
74
75
# File 'lib/ukiryu/response/base.rb', line 73

def stderr
  @result.error_output
end

#stderr_linesArray<String>

Get stderr as lines

Returns:

  • (Array<String>)

    the stderr split into lines



87
88
89
# File 'lib/ukiryu/response/base.rb', line 87

def stderr_lines
  @result.stderr_lines
end

#stdoutString

Get the standard output

Returns:

  • (String)

    the stdout content



66
67
68
# File 'lib/ukiryu/response/base.rb', line 66

def stdout
  @result.output
end

#stdout_linesArray<String>

Get stdout as lines

Returns:

  • (Array<String>)

    the stdout split into 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

Returns:

  • (Boolean)

    true if exit code was 0



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

Returns:

  • (Boolean)

    true if the command exceeded its timeout



150
151
152
# File 'lib/ukiryu/response/base.rb', line 150

def timed_out?
  @result.timeout_exceeded?
end

#to_hHash Also known as: to_hash

Convert to hash representation

Returns:

  • (Hash)

    hash representation of the response



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_sString

String representation

Returns:

  • (String)

    summary of the response



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