Class: Kawaii::App
- Inherits:
-
Object
- Object
- Kawaii::App
- Defined in:
- lib/kawaii/app.rb
Class Method Summary collapse
- .handle_route_not_found(error) ⇒ Object
- .process_request(env) ⇒ Object
- .rack_builder ⇒ Object
- .route_not_found(&block) ⇒ Object
- .router ⇒ Object
- .use(middleware, *args, &block) ⇒ Object
Instance Method Summary collapse
Class Method Details
.handle_route_not_found(error) ⇒ Object
35 36 37 38 |
# File 'lib/kawaii/app.rb', line 35 def handle_route_not_found(error) handler = @exception_handler || error_handler(error) handler.call(error) end |
.process_request(env) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/kawaii/app.rb', line 20 def process_request(env) route = router.match(env) rack_builder.run route.handler handler = rack_builder.to_app handler.call(env) end |
.rack_builder ⇒ Object
27 28 29 |
# File 'lib/kawaii/app.rb', line 27 def rack_builder @rack_builder ||= Rack::Builder.new end |
.route_not_found(&block) ⇒ Object
16 17 18 |
# File 'lib/kawaii/app.rb', line 16 def route_not_found(&block) @exception_handler = block end |
.use(middleware, *args, &block) ⇒ Object
12 13 14 |
# File 'lib/kawaii/app.rb', line 12 def use(middleware, *args, &block) rack_builder.use(middleware, *args, &block) end |
Instance Method Details
#call(env) ⇒ Object
4 5 6 7 8 |
# File 'lib/kawaii/app.rb', line 4 def call(env) self.class.process_request(env) rescue Kawaii::RouteNotFound => error self.class.handle_route_not_found(error) end |