Class: Minfra::Cli::Runner::Result

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/minfra/cli/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#debug, #deprecated, #error, #exit_error, #info, #warn

Constructor Details

#initialize(on_output: nil) ⇒ Result

Returns a new instance of Result.



16
17
18
19
20
21
# File 'lib/minfra/cli/runner.rb', line 16

def initialize(on_output: nil)
  @stderr_lines = []
  @stdout_lines = []
  @status = nil
  @on_output = on_output
end

Instance Attribute Details

#status=(value) ⇒ Object (writeonly)

Sets the attribute status

Parameters:

  • value

    the value to set the attribute status to.



12
13
14
# File 'lib/minfra/cli/runner.rb', line 12

def status=(value)
  @status = value
end

#stdout_linesObject (readonly)

Returns the value of attribute stdout_lines.



14
15
16
# File 'lib/minfra/cli/runner.rb', line 14

def stdout_lines
  @stdout_lines
end

Instance Method Details

#add(line, stream = :stdout) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/minfra/cli/runner.rb', line 23

def add(line, stream = :stdout)
  line.chomp!
  @on_output.call(line, stream) if @on_output
  if stream == :stdout
    @stdout_lines << line
    debug line
  else
    @stderr_lines << line
    info line
  end
end

#error?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/minfra/cli/runner.rb', line 43

def error?
  !success?
end

#exitstatusObject



35
36
37
# File 'lib/minfra/cli/runner.rb', line 35

def exitstatus
  @status.exitstatus
end

#stderrObject



51
52
53
# File 'lib/minfra/cli/runner.rb', line 51

def stderr
  @stderr_lines.join("\n")
end

#stdoutObject



47
48
49
# File 'lib/minfra/cli/runner.rb', line 47

def stdout
  @stdout_lines.join("\n")
end

#success?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/minfra/cli/runner.rb', line 39

def success?
  @status.success?
end

#to_sObject



55
56
57
# File 'lib/minfra/cli/runner.rb', line 55

def to_s
  stdout
end