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.



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

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.



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

def original
  @original
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

Instance Method Details

#extract_childprocessObject



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

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



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

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