Class: AutoBrewster::Server
- Inherits:
-
Object
- Object
- AutoBrewster::Server
- Defined in:
- lib/auto_brewster/server.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#port ⇒ Object
Returns the value of attribute port.
-
#rackup_path ⇒ Object
Returns the value of attribute rackup_path.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #get_host_with_protocol_and_port ⇒ Object
-
#initialize(server, port, rackup_path = 'config.ru', hostname = false) ⇒ Server
constructor
A new instance of Server.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(server, port, rackup_path = 'config.ru', hostname = false) ⇒ Server
Returns a new instance of Server.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/auto_brewster/server.rb', line 13 def initialize(server, port, rackup_path = 'config.ru', hostname = false) ENV['RACK_ENV'] ||= 'test' @port = port @server = server @rackup_path = rackup_path @hostname = hostname @app = build_rack_app @middleware = AutoBrewster::Middleware.new(@app) end |
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
7 8 9 |
# File 'lib/auto_brewster/server.rb', line 7 def app @app end |
#hostname ⇒ Object
Returns the value of attribute hostname.
7 8 9 |
# File 'lib/auto_brewster/server.rb', line 7 def hostname @hostname end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/auto_brewster/server.rb', line 7 def port @port end |
#rackup_path ⇒ Object
Returns the value of attribute rackup_path.
7 8 9 |
# File 'lib/auto_brewster/server.rb', line 7 def rackup_path @rackup_path end |
#server ⇒ Object
Returns the value of attribute server.
7 8 9 |
# File 'lib/auto_brewster/server.rb', line 7 def server @server end |
Instance Method Details
#get_host_with_protocol_and_port ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/auto_brewster/server.rb', line 39 def get_host_with_protocol_and_port if @hostname return @hostname else return "http://127.0.0.1:#{@port}" end end |
#start ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/auto_brewster/server.rb', line 25 def start @server_thread = Thread.new do @server.call(@middleware, @port) end Timeout.timeout(10) { @server_thread.join(0.1) until responsive? } end |
#stop ⇒ Object
33 34 35 36 37 |
# File 'lib/auto_brewster/server.rb', line 33 def stop return if @server_thread.nil? @server_thread.kill Timeout.timeout(10) { @server_thread.join(0.1) until !responsive? } end |