Class: FunRun

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

Instance Method Summary collapse

Constructor Details

#initialize(command) ⇒ FunRun

Returns a new instance of FunRun.



4
5
6
7
# File 'lib/funrun.rb', line 4

def initialize(command)
  @command = command
  @output = StringIO.new
end

Instance Method Details

#start(options = {}, &started_check) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/funrun.rb', line 8

def start(options={}, &started_check)
  check_period = options[:check_period] || 0.1
  output = options[:output] || @output

  output.print 'starting...'
  @pid = Kernel.spawn(@command)
  if started_check
    until call(&started_check) do
      output.print '.'
      sleep check_period
    end
  end
  output.puts "ok (#{@pid})"
  self
end

#stopObject



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

def stop
  Process.kill 'KILL', @pid
  Process.wait @pid
end

#tcp_check(port) ⇒ Object



27
28
29
30
# File 'lib/funrun.rb', line 27

def tcp_check(port)
  TCPSocket.new('localhost', port).close
  true
end