16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/eksa.rb', line 16
def call(env)
request = Rack::Request.new(env)
flash_message = request.cookies['eksa_flash']
route = @routes[request.path_info]
if route
controller_instance = route[:controller].new(request)
controller_instance.flash[:notice] = flash_message if flash_message
response_body = controller_instance.send(route[:action])
response = Rack::Response.new
if controller_instance.status == 302
response.redirect(controller_instance.redirect_url, 302)
else
response.write(response_body)
response['content-type'] = 'text/html'
end
response.delete_cookie('eksa_flash') if flash_message
response.finish
else
[404, { 'content-type' => 'text/html' }, ["<h1>404 - Not Found</h1>"]]
end
end
|