Class: Lxc::CommandResult

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

Overview

Result of command

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CommandResult

Create new instance

Parameters:

  • result (Object)

    result of command



201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/elecksee/helpers.rb', line 201

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
  elsif(result.class.to_s == 'Rye::Err' || result.class.to_s == 'Rye::Rap')
    extract_rye
  else
    raise TypeError.new("Unknown process result type received: #{result.class}")
  end
end

Instance Attribute Details

#originalObject (readonly)

Returns original result.

Returns:

  • (Object)

    original result



192
193
194
# File 'lib/elecksee/helpers.rb', line 192

def original
  @original
end

#stderrIO (readonly)

Returns stderr of command.

Returns:

  • (IO)

    stderr of command



196
197
198
# File 'lib/elecksee/helpers.rb', line 196

def stderr
  @stderr
end

#stdoutIO (readonly)

Returns stdout of command.

Returns:

  • (IO)

    stdout of command



194
195
196
# File 'lib/elecksee/helpers.rb', line 194

def stdout
  @stdout
end

Instance Method Details

#extract_childprocessObject

Extract information from childprocess result



215
216
217
218
219
220
221
222
# File 'lib/elecksee/helpers.rb', line 215

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_ryeObject

Extract information from rye result



231
232
233
234
# File 'lib/elecksee/helpers.rb', line 231

def extract_rye
  @stdout = original.stdout.map(&:to_s).join("\n")
  @stderr = original.stderr.map(&:to_s).join("\n")
end

#extract_shelloutObject

Extract information from mixlib shellout result



225
226
227
228
# File 'lib/elecksee/helpers.rb', line 225

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