Class: Backspin::CommandResult

Inherits:
Object
  • Object
show all
Defined in:
lib/backspin/command_result.rb

Overview

Represents the result of executing a command Stores stdout, stderr, and exit status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout:, stderr:, status:) ⇒ CommandResult

Returns a new instance of CommandResult.



9
10
11
12
13
# File 'lib/backspin/command_result.rb', line 9

def initialize(stdout:, stderr:, status:)
  @stdout = stdout
  @stderr = stderr
  @status = normalize_status(status)
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/backspin/command_result.rb', line 7

def status
  @status
end

#stderrObject (readonly)

Returns the value of attribute stderr.



7
8
9
# File 'lib/backspin/command_result.rb', line 7

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



7
8
9
# File 'lib/backspin/command_result.rb', line 7

def stdout
  @stdout
end

Instance Method Details

#==(other) ⇒ Object

Compare two results for equality



35
36
37
38
39
# File 'lib/backspin/command_result.rb', line 35

def ==(other)
  return false unless other.is_a?(CommandResult)

  stdout == other.stdout && stderr == other.stderr && status == other.status
end

#failure?Boolean

Returns true if the command failed (non-zero exit status).

Returns:

  • (Boolean)

    true if the command failed (non-zero exit status)



21
22
23
# File 'lib/backspin/command_result.rb', line 21

def failure?
  !success?
end

#inspectObject



41
42
43
# File 'lib/backspin/command_result.rb', line 41

def inspect
  "#<Backspin::CommandResult status=#{status} stdout=#{stdout} stderr=#{stderr}>"
end

#success?Boolean

Returns true if the command succeeded (exit status 0).

Returns:

  • (Boolean)

    true if the command succeeded (exit status 0)



16
17
18
# File 'lib/backspin/command_result.rb', line 16

def success?
  status.zero?
end

#to_hHash

Returns Hash representation of the result.

Returns:

  • (Hash)

    Hash representation of the result



26
27
28
29
30
31
32
# File 'lib/backspin/command_result.rb', line 26

def to_h
  {
    "stdout" => stdout,
    "stderr" => stderr,
    "status" => status
  }
end