Class: Ww::Server

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/ww/server.rb

Constant Summary collapse

@@servers =
{}
@@handler =
:webrick

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#appObject (readonly)

Returns the value of attribute app.



53
54
55
# File 'lib/ww/server.rb', line 53

def app
  @app
end

#portObject (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

Raises:

  • (ArgumentError)


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

.handlerObject



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

.serversObject



13
# File 'lib/ww/server.rb', line 13

def servers; @@servers; end

Instance Method Details

#running?Boolean

Returns:

  • (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_onceObject



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