class ExceptionViewer
Attributes
app[R]
exception[R]
res[R]
Public Class Methods
new(app)
click to toggle source
# File lib/laris/exception_viewer.rb, line 4 def initialize(app) @app = app @res = Rack::Response.new @exception = nil end
Public Instance Methods
call(env)
click to toggle source
# File lib/laris/exception_viewer.rb, line 10 def call(env) begin app.call(env) rescue => e @exception = e exception_page end end
Private Instance Methods
backtrace()
click to toggle source
# File lib/laris/exception_viewer.rb, line 32 def backtrace exception.backtrace end
code_preview()
click to toggle source
# File lib/laris/exception_viewer.rb, line 44 def code_preview match_data = source.match(/^(.+):(\d+)(:in.+)?$/) file_name, line = match_data.captures lines = File.readlines(file_name).map(&:chomp) i = line.to_i - 1 lines[i] << "<b> <---------- What were you thinking?</b>" 3.times do i -= 1 if i > 0 end lines[i, 6].join('<br>') end
content()
click to toggle source
# File lib/laris/exception_viewer.rb, line 27 def content template = File.read("#{File.dirname(__FILE__)}/exception_view.html.erb") ERB.new(template).result(binding) end
exception_page()
click to toggle source
# File lib/laris/exception_viewer.rb, line 20 def exception_page res.status = 500 res["Content-Type"] = "text/html" res.write(content) res.finish end
message()
click to toggle source
# File lib/laris/exception_viewer.rb, line 40 def message exception.message end
source()
click to toggle source
# File lib/laris/exception_viewer.rb, line 36 def source backtrace.first end