class Launchy::Rails::Opener
Public Class Methods
new(protocol, host, port)
click to toggle source
# File lib/launchy/rails/opener.rb, line 4 def initialize(protocol, host, port) @host = host @port = port @protocol = protocol end
Public Instance Methods
open_when_ready()
click to toggle source
# File lib/launchy/rails/opener.rb, line 10 def open_when_ready url = "#{@protocol}://#{@host}:#{@port}" Thread.new do while !port_open?(@host, @port, 1) sleep 1 end Launchy.open(url) end end
port_open?(ip, port, seconds=1)
click to toggle source
# File lib/launchy/rails/opener.rb, line 20 def port_open?(ip, port, seconds=1) Timeout::timeout(seconds) do begin TCPSocket.new(ip, port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end end rescue Timeout::Error false end