Class: EacRubyUtils::Envs::Spawn

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_ruby_utils/envs/spawn.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ Spawn

Returns a new instance of Spawn.



8
9
10
11
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 8

def initialize(command)
  @command = command
  @pid = ::Process.spawn(command)
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



6
7
8
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 6

def command
  @command
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 6

def pid
  @pid
end

Instance Method Details

#kill(signal) ⇒ Object



13
14
15
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 13

def kill(signal)
  ::Process.kill(signal, pid)
end

#kill_at_end(&block) ⇒ Object



17
18
19
20
21
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 17

def kill_at_end(&block)
  block.call(self)
ensure
  kill('KILL')
end

#to_hObject



23
24
25
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 23

def to_h
  { command: command, pid: pid }
end

#waitObject



27
28
29
# File 'lib/eac_ruby_utils/envs/spawn.rb', line 27

def wait
  ::Process.wait pid
end