Class: Dotanuki::ExecResult

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

Overview

Result of one or more command executions

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExecResult

Returns a new instance of ExecResult.



44
45
46
47
48
49
# File 'lib/dotanuki.rb', line 44

def initialize
  @stdout = []
  @stderr = []
  @status = 0
  @failed_index = nil
end

Instance Attribute Details

#failed_indexFixnum (readonly)

Index of the command that failed, or nil if all commands succeeded

Returns:

  • (Fixnum)


42
43
44
# File 'lib/dotanuki.rb', line 42

def failed_index
  @failed_index
end

#statusFixnum (readonly)

Exit status of the command that failed, nil if the command was not found and 0 if all commands succeeded

Returns:

  • (Fixnum)


38
39
40
# File 'lib/dotanuki.rb', line 38

def status
  @status
end

#stderrArray (readonly)

Array of stderr from each command executed

Returns:

  • (Array)


32
33
34
# File 'lib/dotanuki.rb', line 32

def stderr
  @stderr
end

#stdoutArray (readonly)

Array of stdout from each command executed

Returns:

  • (Array)


28
29
30
# File 'lib/dotanuki.rb', line 28

def stdout
  @stdout
end

Instance Method Details

#<<(result) ⇒ Object

Add another [ExecResult] to this

Raises:

  • (ArgumentError)


77
78
79
80
81
# File 'lib/dotanuki.rb', line 77

def <<(result)
  raise ArgumentError unless result.is_a?(ExecResult)
  # TODO merge correctly
  add(result.stdout, result.stderr, result.status)
end

#add(stdout, stderr, status) ⇒ Object

Add the result of a command execution



67
68
69
70
71
72
73
74
# File 'lib/dotanuki.rb', line 67

def add(stdout, stderr, status)
  @stdout << stdout
  @stderr << stderr
  if status.nil? || status != 0
    @status = status
    @failed_index = @stdout.size - 1
  end
end

#fail_messageObject

Returns stderr for the command that failed



62
63
64
# File 'lib/dotanuki.rb', line 62

def fail_message
  stderr[@failed_index]
end

#failed?Boolean

Returns true if a command has failed

Returns:

  • (Boolean)


52
53
54
# File 'lib/dotanuki.rb', line 52

def failed?
  status != 0
end

#ok?Boolean

Returns true if a command has not failed

Returns:

  • (Boolean)


57
58
59
# File 'lib/dotanuki.rb', line 57

def ok?
  status == 0
end