Class: ReaperMan::Utils::Process::CommandResult

Inherits:
Object
  • Object
show all
Defined in:
lib/reaper-man/utils/process.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CommandResult

Returns a new instance of CommandResult.



31
32
33
34
35
36
37
38
39
40
# File 'lib/reaper-man/utils/process.rb', line 31

def initialize(result)
  @original = result
  if result.class.ancestors.map(&:to_s).include?("ChildProcess::AbstractProcess")
    extract_childprocess
  elsif result.class.to_s == "Mixlib::ShellOut"
    extract_shellout
  else
    raise TypeError.new("Unknown process result type received: #{result.class}")
  end
end

Instance Attribute Details

#originalObject (readonly)

Returns the value of attribute original.



29
30
31
# File 'lib/reaper-man/utils/process.rb', line 29

def original
  @original
end

#stderrObject (readonly)

Returns the value of attribute stderr.



29
30
31
# File 'lib/reaper-man/utils/process.rb', line 29

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



29
30
31
# File 'lib/reaper-man/utils/process.rb', line 29

def stdout
  @stdout
end

Instance Method Details

#extract_childprocessObject



42
43
44
45
46
47
48
49
# File 'lib/reaper-man/utils/process.rb', line 42

def extract_childprocess
  original.io.stdout.rewind
  original.io.stderr.rewind
  @stdout = original.io.stdout.read
  @stderr = original.io.stderr.read
  original.io.stdout.delete
  original.io.stderr.delete
end

#extract_shelloutObject



51
52
53
54
# File 'lib/reaper-man/utils/process.rb', line 51

def extract_shellout
  @stdout = original.stdout
  @stderr = original.stderr
end