Class: Pione::TestHelper::WebServer
- Inherits:
-
Object
- Object
- Pione::TestHelper::WebServer
- Defined in:
- lib/pione/test-helper/webserver.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(document_root, option = {}) ⇒ WebServer
constructor
A new instance of WebServer.
- #port ⇒ Object
- #root ⇒ Object
- #start ⇒ Object
- #terminate ⇒ Object
Constructor Details
#initialize(document_root, option = {}) ⇒ WebServer
Returns a new instance of WebServer.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/pione/test-helper/webserver.rb', line 13 def initialize(document_root, option={}) logger = WEBrick::Log.new(StringIO.new("", "w")) # modify document root document_root = document_root.local.path if document_root.kind_of?(Pione::Location::DataLocation) # setup options _option = {DocumentRoot: document_root} _option[:Port] = 54673 unless option[:Port] _option[:Logger] = logger unless option[:Logger] _option[:AccessLog] = logger unless option[:AccessLog] # make webrick @server = WEBrick::HTTPServer.new(_option) end |
Class Method Details
.start(*args) ⇒ Object
8 9 10 |
# File 'lib/pione/test-helper/webserver.rb', line 8 def start(*args) new(*args).tap {|x| x.start} end |
Instance Method Details
#port ⇒ Object
32 33 34 |
# File 'lib/pione/test-helper/webserver.rb', line 32 def port @server.config[:Port] end |
#root ⇒ Object
28 29 30 |
# File 'lib/pione/test-helper/webserver.rb', line 28 def root Pione::Location["http://localhost:%s/" % port] end |
#start ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/pione/test-helper/webserver.rb', line 36 def start @thread = Thread.new do retriable(on: WEBrick::ServerError, tries: 10, interval: 2) do @server.start end end end |
#terminate ⇒ Object
44 45 46 47 |
# File 'lib/pione/test-helper/webserver.rb', line 44 def terminate @server.shutdown @thread.kill.join end |