Class: Teaspoon::Server
- Inherits:
-
Object
- Object
- Teaspoon::Server
- Defined in:
- lib/teaspoon/server.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #responsive? ⇒ Boolean
- #start ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
10 11 12 |
# File 'lib/teaspoon/server.rb', line 10 def initialize @port = Teaspoon.configuration.server_port || find_available_port end |
Instance Attribute Details
#port ⇒ Object
Returns the value of attribute port.
8 9 10 |
# File 'lib/teaspoon/server.rb', line 8 def port @port end |
Instance Method Details
#responsive? ⇒ Boolean
25 26 27 28 29 30 |
# File 'lib/teaspoon/server.rb', line 25 def responsive? TCPSocket.new("127.0.0.1", port).close true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH false end |
#start ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/teaspoon/server.rb', line 14 def start thread = Thread.new do disable_logging server = Rack::Server.new() server.start end wait_until_started(thread) rescue => e raise Teaspoon::ServerException, "Cannot start server: #{e.message}" end |
#url ⇒ Object
32 33 34 |
# File 'lib/teaspoon/server.rb', line 32 def url "http://127.0.0.1:#{port}" end |