Class: Intermodal::Rack::Rescue
- Inherits:
-
Object
- Object
- Intermodal::Rack::Rescue
- Includes:
- ActionController::Rescue
- Defined in:
- lib/intermodal/rack/rescue.rb
Class Method Summary collapse
Instance Method Summary collapse
- #call(env) ⇒ Object
- #content_type(format) ⇒ Object
-
#initialize(app, &block) ⇒ Rescue
constructor
A new instance of Rescue.
-
#rescue_with_handler(exception) ⇒ Object
Overrides ActiveSuppor::Rescuable#rescue_with_handler All handlers MUST respond with a valid Rack response.
- #watch(x) ⇒ Object
Constructor Details
#initialize(app, &block) ⇒ Rescue
Returns a new instance of Rescue.
63 64 65 66 |
# File 'lib/intermodal/rack/rescue.rb', line 63 def initialize(app, &block) @app = app self.class.instance_eval(&block) if block_given? end |
Class Method Details
.watch(x) ⇒ Object
8 9 10 |
# File 'lib/intermodal/rack/rescue.rb', line 8 def self.watch(x) ap x if defined? ap end |
Instance Method Details
#call(env) ⇒ Object
68 69 70 71 72 |
# File 'lib/intermodal/rack/rescue.rb', line 68 def call(env) @app.call(env) rescue Exception => exception rescue_with_handler(exception) || raise(exception) end |
#content_type(format) ⇒ Object
59 60 61 |
# File 'lib/intermodal/rack/rescue.rb', line 59 def content_type(format) "#{Mime::Type.lookup_by_extension(format)}; charset=utf-8" end |
#rescue_with_handler(exception) ⇒ Object
Overrides ActiveSuppor::Rescuable#rescue_with_handler All handlers MUST respond with a valid Rack response
76 77 78 79 |
# File 'lib/intermodal/rack/rescue.rb', line 76 def rescue_with_handler(exception) return unless handler = handler_for_rescue(exception) handler.arity != 0 ? handler.call(exception) : handler.call end |
#watch(x) ⇒ Object
12 13 14 |
# File 'lib/intermodal/rack/rescue.rb', line 12 def watch(x) self.class.watch(x) end |