Class: Rack::RouteExceptions
- Inherits:
- Object
- Defined in:
- ramaze/lib/vendor/route_exceptions.rb
Constant Summary
- ROUTES =
[]
- PATH_INFO =
'rack.route_exceptions.path_info'.freeze
- EXCEPTION =
'rack.route_exceptions.exception'.freeze
Class Method Summary
- + (Object) route(exception, to) (also: []=)
Instance Method Summary
- - (Object) call(env, try_again = true)
- - (RouteExceptions) initialize(app) constructor A new instance of RouteExceptions.
- - (Object) route(to, env, exception)
Constructor Details
- (RouteExceptions) initialize(app)
A new instance of RouteExceptions
17 18 19 |
# File 'ramaze/lib/vendor/route_exceptions.rb', line 17 def initialize(app) @app = app end |
Class Method Details
+ (Object) route(exception, to) Also known as: []=
9 10 11 12 |
# File 'ramaze/lib/vendor/route_exceptions.rb', line 9 def route(exception, to) ROUTES.delete_if{|k,v| k == exception } ROUTES << [exception, to] end |
Instance Method Details
- (Object) call(env, try_again = true)
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'ramaze/lib/vendor/route_exceptions.rb', line 21 def call(env, try_again = true) @app.call(env) rescue Exception => exception raise(exception) unless try_again ROUTES.each do |klass, to| next unless klass === exception return route(to, env, exception) end raise(exception) end |
- (Object) route(to, env, exception)
34 35 36 37 38 39 40 |
# File 'ramaze/lib/vendor/route_exceptions.rb', line 34 def route(to, env, exception) env.merge!( PATH_INFO => env['PATH_INFO'], EXCEPTION => exception, 'PATH_INFO' => to) call(env, try_again = false) end |