class WAB::Impl::Sinatra::TqlHandler

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

Public Class Methods

new(shell) click to toggle source
# File lib/wab/impl/sinatra/tql_handler.rb, line 11
def initialize(shell)
  @shell = shell
end

Public Instance Methods

call(req) click to toggle source
# File lib/wab/impl/sinatra/tql_handler.rb, line 15
def call(req)
  path = (req.script_name + req.path_info).split('/')[1..-1]
  query = parse_query(req.query_string)
  tql = Oj.load(req.body, mode: :wab)
  log_request_with_body('TQL', path, query, tql) if @shell.logger.info?
  send_result(@shell.query(tql), path, query)
rescue StandardError => e
  send_error(e, res)
end

Private Instance Methods

log_request_with_body(caller, path, query, body) click to toggle source
# File lib/wab/impl/sinatra/tql_handler.rb, line 27
def log_request_with_body(caller, path, query, body)
  body = Data.new(body) unless body.is_a?(WAB::Data)
  @shell.logger.info("#{caller} #{path.join('/')}#{query}\n#{body.json(@shell.indent)}")
end