Class: Nonnative::System

Inherits:
Object
  • Object
show all
Defined in:
lib/nonnative/system.rb

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ System

Returns a new instance of System.



5
6
7
8
# File 'lib/nonnative/system.rb', line 5

def initialize(process)
  @process = process
  @started = false
end

Instance Method Details

#startObject



10
11
12
13
14
15
16
17
# File 'lib/nonnative/system.rb', line 10

def start
  unless started
    @pid = spawn(process.command, %i[out err] => [process.file, 'a'])
    @started = true
  end

  pid
end

#stopObject

Raises:



19
20
21
22
23
24
25
26
# File 'lib/nonnative/system.rb', line 19

def stop
  raise Nonnative::Error, "Can't stop a process that has not started" unless started

  ::Process.kill('SIGINT', pid)
  @started = false

  pid
end