Class: Psychic::Shell::ExecutionResult

Inherits:
Object
  • Object
show all
Includes:
Util::Hashable
Defined in:
lib/psychic/shell/execution_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Util::Hashable

#to_hash

Constructor Details

#initialize(results) ⇒ ExecutionResult

Returns a new instance of ExecutionResult.



17
18
19
20
21
22
# File 'lib/psychic/shell/execution_result.rb', line 17

def initialize(results)
  @exitstatus = results.fetch(:exitstatus)
  # Needs to be UTF-8 to serialize as YAML
  @stdout = results.fetch(:stdout).force_encoding('utf-8')
  @stderr = results.fetch(:stderr).force_encoding('utf-8')
end

Instance Attribute Details

#exitstatusObject (readonly)

Returns the value of attribute exitstatus.



10
11
12
# File 'lib/psychic/shell/execution_result.rb', line 10

def exitstatus
  @exitstatus
end

#stderrObject (readonly)

Returns the value of attribute stderr.



12
13
14
# File 'lib/psychic/shell/execution_result.rb', line 12

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



11
12
13
# File 'lib/psychic/shell/execution_result.rb', line 11

def stdout
  @stdout
end

Instance Method Details

#error!Object



24
25
26
27
28
29
30
# File 'lib/psychic/shell/execution_result.rb', line 24

def error!
  if @exitstatus != 0
    error = ExecutionError.new
    error.execution_result = self
    fail error
  end
end

#to_sObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/psychic/shell/execution_result.rb', line 32

def to_s
  ''"
  Execution Result:
    exitstatus: #{exitstatus}
    stdout:
  #{stdout}
    stderr:
  #{stderr}
  "''
end