Class: Acouchi::ProcessLauncher

Inherits:
Object
  • Object
show all
Defined in:
lib/acouchi/process_launcher.rb

Constant Summary collapse

DEFAULT_START_OPTIONS =
{:inherit_io => true}

Instance Method Summary collapse

Constructor Details

#initialize(*arguments) ⇒ ProcessLauncher

Returns a new instance of ProcessLauncher.



7
8
9
10
11
# File 'lib/acouchi/process_launcher.rb', line 7

def initialize(*arguments)
  @arguments = arguments
  @process = ChildProcess.build(*@arguments)
  self
end

Instance Method Details

#startObject



18
19
20
21
# File 'lib/acouchi/process_launcher.rb', line 18

def start
  @process.start
  self
end

#start_and_crash_if_process_failsObject



33
34
35
36
37
38
39
# File 'lib/acouchi/process_launcher.rb', line 33

def start_and_crash_if_process_fails
  start.wait
  if @process.crashed?
    raise "A process exited with a non-zero exit code.\nThe command executed was \"#{@arguments.join(" ")}\""
  end
  self
end

#start_in_backgroundObject



28
29
30
31
# File 'lib/acouchi/process_launcher.rb', line 28

def start_in_background
  @process.start
  self
end

#waitObject



23
24
25
26
# File 'lib/acouchi/process_launcher.rb', line 23

def wait
  @process.wait
  self
end

#with_inherited_ioObject



13
14
15
16
# File 'lib/acouchi/process_launcher.rb', line 13

def with_inherited_io
  @process.io.inherit!
  self
end