From 8ae9b05fa0ca579ecabcd563e6ba75ea0f44f074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Mon, 3 May 2010 12:54:52 +0200 Subject: Make backtrace_cleaner work as expected. Prior to this patch, the Full Trace rarely showed the full trace. Also, increase performance considerably. --- railties/lib/rails/backtrace_cleaner.rb | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'railties/lib/rails') diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb index ee2635d4cd..bedefaa51c 100644 --- a/railties/lib/rails/backtrace_cleaner.rb +++ b/railties/lib/rails/backtrace_cleaner.rb @@ -2,29 +2,28 @@ require 'active_support/backtrace_cleaner' module Rails class BacktraceCleaner < ActiveSupport::BacktraceCleaner - ERB_METHOD_SIG = /:in `_run_erb_.*/ - APP_DIRS = %w( app config lib test ) + APP_DIRS_PATTERN = /^\/?(app|config|lib|test)/ + RENDER_TEMPLATE_PATTERN = /:in `_render_template_\w*'/ def initialize super add_filter { |line| line.sub("#{Rails.root}/", '') } - add_filter { |line| line.sub(ERB_METHOD_SIG, '') } + add_filter { |line| line.sub(RENDER_TEMPLATE_PATTERN, '') } add_filter { |line| line.sub('./', '/') } # for tests add_gem_filters - - add_silencer { |line| !APP_DIRS.any? { |dir| line =~ /^\/?#{dir}/ } } + add_silencer { |line| line !~ APP_DIRS_PATTERN } end private def add_gem_filters - return unless defined? Gem - (Gem.path + [Gem.default_dir]).uniq.each do |path| - # http://gist.github.com/30430 - add_filter { |line| - line.sub(%r{(#{path})/gems/([^/]+)-([0-9.]+)/(.*)}, '\2 (\3) \4') - } - end + return unless defined?(Gem) + + gems_paths = (Gem.path + [Gem.default_dir]).uniq.map!{ |p| Regexp.escape(p) } + return if gems_paths.empty? + + gems_regexp = %r{(#{gems_paths.join('|')})/gems/([^/]+)-([\w\.]+)/(.*)} + add_filter { |line| line.sub(gems_regexp, '\2 (\3) \4') } end end -- cgit v1.2.3