Class: Nonnative::Command

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

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ Command

Returns a new instance of Command.



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

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

Instance Method Details

#nameObject



10
11
12
# File 'lib/nonnative/command.rb', line 10

def name
  process.command
end

#startObject



14
15
16
17
18
19
20
21
# File 'lib/nonnative/command.rb', line 14

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

  pid
end

#stopObject

Raises:



23
24
25
26
27
28
29
30
# File 'lib/nonnative/command.rb', line 23

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

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

  pid
end