Class: FunRun
- Inherits:
-
Object
- Object
- FunRun
- Defined in:
- lib/funrun.rb
Instance Method Summary collapse
-
#initialize(command) ⇒ FunRun
constructor
A new instance of FunRun.
- #start(options = {}, &started_check) ⇒ Object
- #stop ⇒ Object
- #tcp_check(port) ⇒ Object
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(={}, &started_check) check_period = [:check_period] || 0.1 output = [: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 |
#stop ⇒ Object
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 |