Class: Ww::Server
Constant Summary collapse
- @@servers =
{}
- @@handler =
:webrick
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
- .[](name) ⇒ Object
- .[]=(name, server) ⇒ Object
- .build_double(port, &block) ⇒ Object
- .detect_server(args) ⇒ Object
- .handler ⇒ Object
- .handler=(v) ⇒ Object
- .servers ⇒ Object
Instance Method Summary collapse
-
#initialize(app, port) ⇒ Server
constructor
A new instance of Server.
- #running? ⇒ Boolean
- #shutdown! ⇒ Object
- #start! ⇒ Object
- #start_once ⇒ Object
Constructor Details
#initialize(app, port) ⇒ Server
Returns a new instance of Server.
55 56 57 58 59 |
# File 'lib/ww/server.rb', line 55 def initialize(app, port) @app = app @port = port @handler = ::Rack::Handler.get(self.class.handler) end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
53 54 55 |
# File 'lib/ww/server.rb', line 53 def app @app end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
53 54 55 |
# File 'lib/ww/server.rb', line 53 def port @port end |
Class Method Details
.[](name) ⇒ Object
18 |
# File 'lib/ww/server.rb', line 18 def [](name); @@servers[name] ; end |
.[]=(name, server) ⇒ Object
19 |
# File 'lib/ww/server.rb', line 19 def []=(name, server); @@servers[name] = server ; end |
.build_double(port, &block) ⇒ Object
21 22 23 |
# File 'lib/ww/server.rb', line 21 def build_double(port, &block) new(Application.new(&block), port) end |
.detect_server(args) ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/ww/server.rb', line 25 def detect_server(args) if servers.include?(args.first) return self[args.shift] elsif servers.size == 1 return servers.values.first end raise ArgumentError, "Ambigous server" unless server end |
.handler ⇒ Object
15 |
# File 'lib/ww/server.rb', line 15 def handler; @@handler; end |
.handler=(v) ⇒ Object
16 |
# File 'lib/ww/server.rb', line 16 def handler=(v); @@handler = v; end |
.servers ⇒ Object
13 |
# File 'lib/ww/server.rb', line 13 def servers; @@servers; end |
Instance Method Details
#running? ⇒ Boolean
67 |
# File 'lib/ww/server.rb', line 67 def running?; !!@running ; end |
#shutdown! ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/ww/server.rb', line 76 def shutdown! return unless @running shutdown_http_server @thread.kill if @thread.alive? @running = false self end |
#start! ⇒ Object
69 70 71 72 73 74 |
# File 'lib/ww/server.rb', line 69 def start! run_with_picking_server_instance! @running = true at_exit { shutdown! } self end |
#start_once ⇒ Object
61 62 63 64 65 |
# File 'lib/ww/server.rb', line 61 def start_once @app.reset! current_servlet.testing_thread = Thread.current start! unless running? end |