2009-04-28 21:21:03 -04:00
|
|
|
require 'active_support/backtrace_cleaner'
|
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
module Rails
|
|
|
|
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
|
2010-05-03 06:54:52 -04:00
|
|
|
APP_DIRS_PATTERN = /^\/?(app|config|lib|test)/
|
|
|
|
RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/
|
2008-11-22 12:06:08 -05:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
2009-10-16 15:49:39 -04:00
|
|
|
add_filter { |line| line.sub("#{Rails.root}/", '') }
|
2010-05-03 06:54:52 -04:00
|
|
|
add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, '') }
|
2008-11-24 09:43:47 -05:00
|
|
|
add_filter { |line| line.sub('./', '/') } # for tests
|
2009-03-05 15:48:56 -05:00
|
|
|
|
|
|
|
add_gem_filters
|
2010-05-03 06:54:52 -04:00
|
|
|
add_silencer { |line| line !~ APP_DIRS_PATTERN }
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2009-10-20 10:32:26 -04:00
|
|
|
|
2009-03-05 15:48:56 -05:00
|
|
|
private
|
|
|
|
def add_gem_filters
|
2010-05-03 06:54:52 -04:00
|
|
|
return unless defined?(Gem)
|
|
|
|
|
|
|
|
gems_paths = (Gem.path + [Gem.default_dir]).uniq.map!{ |p| Regexp.escape(p) }
|
|
|
|
return if gems_paths.empty?
|
|
|
|
|
2010-10-15 10:31:00 -04:00
|
|
|
gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
|
2010-05-03 06:54:52 -04:00
|
|
|
add_filter { |line| line.sub(gems_regexp, '\2 (\3) \4') }
|
2009-03-05 15:48:56 -05:00
|
|
|
end
|
2008-11-22 12:06:08 -05:00
|
|
|
end
|
2008-12-05 12:24:28 -05:00
|
|
|
end
|