Class: Kawaii::App

Inherits:
Object
  • Object
show all
Defined in:
lib/kawaii/app.rb

Class Method Summary collapse

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_builderObject



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

.routerObject



31
32
33
# File 'lib/kawaii/app.rb', line 31

def router
  @router ||= Router.new
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