Class: WAB::Impl::Handler

Inherits:
WEBrick::HTTPServlet::AbstractServlet
  • Object
show all
Defined in:
lib/wab/impl/handler.rb

Overview

Handler for requests that fall under the path assigned to the Controller. This is used only with the WAB::Impl::Shell.

Instance Method Summary collapse

Constructor Details

#initialize(server, shell) ⇒ Handler

Returns a new instance of Handler.



11
12
13
14
# File 'lib/wab/impl/handler.rb', line 11

def initialize(server, shell)
  super(server)
  @shell = shell
end

Instance Method Details

#do_DELETE(req, res) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/wab/impl/handler.rb', line 40

def do_DELETE(req, res)
  controller, path, query = extract_req(req)
  log_request('controller.delete', path, query) if @shell.logger.info?
  send_result(controller.delete(path, query), res, path, query)
rescue StandardError => e
  send_error(e, res)
end

#do_GET(req, res) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/wab/impl/handler.rb', line 16

def do_GET(req, res)
  controller, path, query = extract_req(req)
  log_request('controller.read', path, query) if @shell.logger.info?
  send_result(controller.read(path, query), res, path, query)
rescue StandardError => e
  send_error(e, res)
end

#do_POST(req, res) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/wab/impl/handler.rb', line 32

def do_POST(req, res)
  controller, path, query, body = extract_req(req)
  log_request_with_body('controller.update', path, query, body) if @shell.logger.info?
  send_result(controller.update(path, query, body), res, path, query)
rescue StandardError => e
  send_error(e, res)
end

#do_PUT(req, res) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/wab/impl/handler.rb', line 24

def do_PUT(req, res)
  controller, path, query, body = extract_req(req)
  log_request_with_body('controller.create', path, query, body) if @shell.logger.info?
  send_result(controller.create(path, query, body), res, path, query)
rescue StandardError => e
  send_error(e, res)
end