Class: Rage::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/application.rb

Instance Method Summary collapse

Constructor Details

#initialize(router) ⇒ Application

Returns a new instance of Application.



4
5
6
7
# File 'lib/rage/application.rb', line 4

def initialize(router)
  @router = router
  @exception_app = build_exception_app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rage/application.rb', line 9

def call(env)
  init_logger

  handler = @router.lookup(env)

  response = if handler
    params = Rage::ParamsParser.prepare(env, handler[:params])
    handler[:handler].call(env, params)
  else
    [404, {}, ["Not Found"]]
  end

rescue Rage::Errors::BadRequest => e
  response = @exception_app.call(400, e)

rescue Exception => e
  response = @exception_app.call(500, e)

ensure
  finalize_logger(env, response, params)
end