Class: Lennarb::Application::RequestHandler
- Inherits:
-
Object
- Object
- Lennarb::Application::RequestHandler
- Defined in:
- lib/lennarb/application/request_handler.rb
Overview
Request handler form Application
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.
12 13 14 |
# File 'lib/lennarb/application/request_handler.rb', line 12 def initialize(app) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
6 7 8 |
# File 'lib/lennarb/application/request_handler.rb', line 6 def app @app end |
Instance Method Details
#call(env) ⇒ Array
Call the app with the environment.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lennarb/application/request_handler.rb', line 22 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 |