2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:47 -04:00
|
|
|
require "active_support/backtrace_cleaner"
|
2009-04-28 21:21:03 -04:00
|
|
|
|
2008-11-22 12:06:08 -05:00
|
|
|
module Rails
|
|
|
|
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
|
2016-05-31 12:46:25 -04:00
|
|
|
APP_DIRS_PATTERN = /^\/?(app|config|lib|test|\(\w*\))/
|
2010-05-03 06:54:52 -04:00
|
|
|
RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/
|
2016-08-06 13:15:47 -04:00
|
|
|
EMPTY_STRING = "".freeze
|
|
|
|
SLASH = "/".freeze
|
|
|
|
DOT_SLASH = "./".freeze
|
2008-11-22 12:06:08 -05:00
|
|
|
|
|
|
|
def initialize
|
|
|
|
super
|
2014-09-26 23:03:18 -04:00
|
|
|
@root = "#{Rails.root}/".freeze
|
|
|
|
add_filter { |line| line.sub(@root, EMPTY_STRING) }
|
|
|
|
add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, EMPTY_STRING) }
|
|
|
|
add_filter { |line| line.sub(DOT_SLASH, SLASH) } # for tests
|
2009-03-05 15:48:56 -05:00
|
|
|
|
|
|
|
add_gem_filters
|
2017-02-13 09:25:08 -05:00
|
|
|
add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
|
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
|
2012-04-02 18:58:40 -04:00
|
|
|
gems_paths = (Gem.path | [Gem.default_dir]).map { |p| Regexp.escape(p) }
|
2010-05-03 06:54:52 -04:00
|
|
|
return if gems_paths.empty?
|
|
|
|
|
2010-10-15 10:31:00 -04:00
|
|
|
gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w.]+)/(.*)}
|
2014-09-26 23:03:18 -04:00
|
|
|
gems_result = '\2 (\3) \4'.freeze
|
|
|
|
add_filter { |line| line.sub(gems_regexp, gems_result) }
|
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
|