Class: SiteDiff::Webserver
- Inherits:
-
Object
- Object
- SiteDiff::Webserver
- Defined in:
- lib/sitediff/webserver.rb,
lib/sitediff/webserver/resultserver.rb
Overview
SiteDiff Web Server.
Direct Known Subclasses
Defined Under Namespace
Classes: FixtureServer, ResultServer
Constant Summary collapse
- DEFAULT_PORT =
Simple web server for testing purposes.
13_080
Instance Attribute Summary collapse
-
#ports ⇒ Object
Returns the value of attribute ports.
Instance Method Summary collapse
-
#initialize(start_port, dirs, opts = {}) ⇒ Webserver
constructor
Serve a list of directories.
-
#kill ⇒ Object
Kills the server.
-
#uris ⇒ Object
Maps URIs to defined ports and returns a list of URIs.
-
#wait ⇒ Object
Waits for the server.
Constructor Details
#initialize(start_port, dirs, opts = {}) ⇒ Webserver
Serve a list of directories.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sitediff/webserver.rb', line 15 def initialize(start_port, dirs, opts = {}) start_port ||= DEFAULT_PORT @ports = (start_port...(start_port + dirs.size)).to_a @dirs = dirs @opts = opts setup start_servers if block_given? yield self kill end end |
Instance Attribute Details
#ports ⇒ Object
Returns the value of attribute ports.
11 12 13 |
# File 'lib/sitediff/webserver.rb', line 11 def ports @ports end |
Instance Method Details
#kill ⇒ Object
Kills the server.
32 33 34 |
# File 'lib/sitediff/webserver.rb', line 32 def kill @threads.each(&:kill) end |
#uris ⇒ Object
Maps URIs to defined ports and returns a list of URIs.
44 45 46 |
# File 'lib/sitediff/webserver.rb', line 44 def uris ports.map { |p| "http://localhost:#{p}" } end |
#wait ⇒ Object
Waits for the server.
38 39 40 |
# File 'lib/sitediff/webserver.rb', line 38 def wait @threads.each(&:join) end |