Class: NeverForget::ExceptionHandler
- Inherits:
-
Object
- Object
- NeverForget::ExceptionHandler
- Defined in:
- lib/never_forget/exception_handler.rb
Constant Summary collapse
- TEMPLATE_FILE =
File.('../list_exceptions.erb', __FILE__)
Instance Method Summary collapse
- #call(env) ⇒ Object
- #exceptions_template ⇒ Object
- #forward(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ ExceptionHandler
constructor
A new instance of ExceptionHandler.
- #render_exceptions_view ⇒ Object
Constructor Details
#initialize(app, options = {}) ⇒ ExceptionHandler
Returns a new instance of ExceptionHandler.
9 10 11 12 |
# File 'lib/never_forget/exception_handler.rb', line 9 def initialize(app, = {}) @app = app @options = {:list_path => '/_exceptions'}.update() end |
Instance Method Details
#call(env) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/never_forget/exception_handler.rb', line 23 def call(env) if env['PATH_INFO'] == File.join('/', @options[:list_path]) body = render_exceptions_view [200, {'content-type' => 'text/html'}, [body]] else forward(env) end end |
#exceptions_template ⇒ Object
39 40 41 |
# File 'lib/never_forget/exception_handler.rb', line 39 def exceptions_template File.read(TEMPLATE_FILE) end |
#forward(env) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/never_forget/exception_handler.rb', line 14 def forward(env) begin @app.call(env) rescue StandardError, ScriptError => error NeverForget.log(error, env) raise error end end |
#render_exceptions_view ⇒ Object
32 33 34 35 36 37 |
# File 'lib/never_forget/exception_handler.rb', line 32 def render_exceptions_view template = Erubis::Eruby.new(exceptions_template) context = Erubis::Context.new(:recent => Exception.recent) context.extend TemplateHelpers template.evaluate(context) end |