Class: SimplerDB::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/simplerdb/server.rb

Instance Method Summary collapse

Constructor Details

#initialize(port = nil) ⇒ Server

Create the server running on the given port



10
11
12
# File 'lib/simplerdb/server.rb', line 10

def initialize(port = nil)
  @port = port || 8087
end

Instance Method Details

#shutdownObject

Shut down the server



28
29
30
# File 'lib/simplerdb/server.rb', line 28

def shutdown
  @server.shutdown
end

#startObject

Run the server on the configured port.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/simplerdb/server.rb', line 15

def start
  config = { :Port => @port }
  @server = WEBrick::HTTPServer.new(config)
  @server.mount("/", SimplerDB::RESTServlet)
  
  ['INT', 'TERM'].each do |signal| 
    trap(signal) { @server.shutdown }
  end
  
  @server.start
end