Class: Lennarb::RequestHandler
- Inherits:
-
Object
- Object
- Lennarb::RequestHandler
- Defined in:
- lib/lennarb/request_handler.rb
Overview
Base class for the request handler.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Instance Method Summary collapse
-
#call(env) ⇒ Array
Call the app with the environment.
-
#initialize(app) ⇒ RequestHandler
constructor
Initialize the request handler.
Constructor Details
#initialize(app) ⇒ RequestHandler
Initialize the request handler.
11 12 13 |
# File 'lib/lennarb/request_handler.rb', line 11 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
5 6 7 |
# File 'lib/lennarb/request_handler.rb', line 5 def app @app end |
Instance Method Details
#call(env) ⇒ Array
Call the app with the environment.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lennarb/request_handler.rb', line 21 def call(env) http_method = env[Rack::REQUEST_METHOD].to_sym parts = env[Rack::PATH_INFO].split("/").reject(&:empty?) block, params = app.routes.match_route(parts, http_method) unless block return [404, {"content-type" => CONTENT_TYPE[:TEXT]}, ["Not Found"]] end req = Request.new(env, params) res = Response.new catch(:halt) do block.call(req, res) res.finish rescue Lennarb::Error => error [500, {"content-type" => CONTENT_TYPE[:TEXT]}, ["Internal Server Error (#{error.})"]] end end |