Class: Ukiryu::Execution::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_infoObject (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

#metadataObject (readonly)

Returns the value of attribute metadata.



10
11
12
# File 'lib/ukiryu/execution/result.rb', line 10

def 
  @metadata
end

#outputString (readonly)

Get stdout as a stripped string

Returns:

  • (String)

    stripped stdout



113
114
115
# File 'lib/ukiryu/execution/result.rb', line 113

def output
  @output
end

Instance Method Details

#commandString

Get the full command string

Returns:

  • (String)

    executed command



21
22
23
# File 'lib/ukiryu/execution/result.rb', line 21

def command
  @command_info.full_command
end

#durationFloat?

Get execution duration

Returns:

  • (Float, nil)

    duration in seconds



85
86
87
# File 'lib/ukiryu/execution/result.rb', line 85

def duration
  @metadata.duration
end

#error_outputString

Get stderr as a stripped string

Returns:

  • (String)

    stripped stderr



120
121
122
# File 'lib/ukiryu/execution/result.rb', line 120

def error_output
  @output.stderr
end

#executableString

Get the executable

Returns:

  • (String)

    executable path



28
29
30
# File 'lib/ukiryu/execution/result.rb', line 28

def executable
  @command_info.executable
end

#executable_nameString

Get the executable name only

Returns:

  • (String)

    executable name



35
36
37
# File 'lib/ukiryu/execution/result.rb', line 35

def executable_name
  @command_info.executable_name
end

#execution_timeFloat?

Get execution duration (alias)

Returns:

  • (Float, nil)

    duration in seconds



92
93
94
# File 'lib/ukiryu/execution/result.rb', line 92

def execution_time
  @metadata.duration_seconds
end

#exit_statusInteger

Get the exit code (alias for status)

Returns:

  • (Integer)

    exit 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

Returns:

  • (Boolean)


106
107
108
# File 'lib/ukiryu/execution/result.rb', line 106

def failure?
  @output.failure?
end

#finished_atTime

Get finish time

Returns:

  • (Time)

    when command finished



78
79
80
# File 'lib/ukiryu/execution/result.rb', line 78

def finished_at
  @metadata.finished_at
end

#inspectString

Inspect

Returns:

  • (String)

    inspection string



189
190
191
# File 'lib/ukiryu/execution/result.rb', line 189

def inspect
  "#<Ukiryu::Execution::Result #{self}>"
end

#started_atTime

Get start time

Returns:

  • (Time)

    when command started



71
72
73
# File 'lib/ukiryu/execution/result.rb', line 71

def started_at
  @metadata.started_at
end

#statusInteger Also known as: exit_code

Get exit status code

Returns:

  • (Integer)

    exit status



56
57
58
# File 'lib/ukiryu/execution/result.rb', line 56

def status
  @output.exit_status
end

#stderrString

Get raw stderr

Returns:

  • (String)

    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

Parameters:

  • pattern (String, Regexp)

    pattern to search for

Returns:

  • (Boolean)

    true if pattern is found



150
151
152
# File 'lib/ukiryu/execution/result.rb', line 150

def stderr_contains?(pattern)
  @output.stderr_contains?(pattern)
end

#stderr_linesArray<String>

Get stderr lines

Returns:

  • (Array<String>)

    stderr split by lines



134
135
136
# File 'lib/ukiryu/execution/result.rb', line 134

def stderr_lines
  @output.stderr_lines
end

#stdoutString

Get raw stdout

Returns:

  • (String)

    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

Parameters:

  • pattern (String, Regexp)

    pattern to search for

Returns:

  • (Boolean)

    true if pattern is found



142
143
144
# File 'lib/ukiryu/execution/result.rb', line 142

def stdout_contains?(pattern)
  @output.stdout_contains?(pattern)
end

#stdout_linesArray<String>

Get stdout lines

Returns:

  • (Array<String>)

    stdout split by 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

Returns:

  • (Boolean)


99
100
101
# File 'lib/ukiryu/execution/result.rb', line 99

def success?
  @output.success?
end

#to_hHash

Get a hash representation of the result

Returns:

  • (Hash)

    result data as a hash



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

Returns:

  • (String)

    result data as JSON



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_sString

String representation of the result

Returns:

  • (String)

    summary string



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