Class: Teabag::Server
- Inherits:
-
Object
- Object
- Teabag::Server
- Defined in:
- lib/teabag/server.rb
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #port ⇒ Object
- #responsive? ⇒ Boolean
- #start ⇒ Object
- #url ⇒ Object
- #wait_until_started ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
8 9 10 11 |
# File 'lib/teabag/server.rb', line 8 def initialize @port = find_available_port Thin::Logging.silent = true if defined?(Thin) end |
Instance Method Details
#port ⇒ Object
42 43 44 |
# File 'lib/teabag/server.rb', line 42 def port @port end |
#responsive? ⇒ Boolean
30 31 32 33 34 35 36 |
# File 'lib/teabag/server.rb', line 30 def responsive? return false if @thread && @thread.join(0) TCPSocket.new("127.0.0.1", port).close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end |
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/teabag/server.rb', line 13 def start STDOUT.print "Starting the Teabag server...\n" unless Teabag.configuration.suppress_log @thread = Thread.new do server = Rack::Server.new() server.start end wait_until_started rescue => e raise "Cannot start server: #{e.}" end |
#url ⇒ Object
38 39 40 |
# File 'lib/teabag/server.rb', line 38 def url "http://127.0.0.1:#{port}" end |
#wait_until_started ⇒ Object
24 25 26 27 28 |
# File 'lib/teabag/server.rb', line 24 def wait_until_started Timeout.timeout(Teabag.configuration.server_timeout) { @thread.join(0.1) until responsive? } rescue Timeout::Error raise "Server failed to start. You may need to increase the timeout configuration." end |