From e714b25723b674bb6d66af40ea9047166907616b Mon Sep 17 00:00:00 2001 From: Nicholas Seckar Date: Tue, 4 Apr 2006 19:37:29 +0000 Subject: Update the diagnostics template skip the useless '' text. Fix symbol extensions test case. Clean paths inside of exception messages and traces. Add Pathname.clean_within for cleaning all the paths inside of a string. git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4158 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/active_support/core_ext/exception.rb | 19 ++++++++++++------- activesupport/lib/active_support/core_ext/pathname.rb | 7 +++++++ .../active_support/core_ext/pathname/clean_within.rb | 14 ++++++++++++++ 3 files changed, 33 insertions(+), 7 deletions(-) create mode 100644 activesupport/lib/active_support/core_ext/pathname.rb create mode 100644 activesupport/lib/active_support/core_ext/pathname/clean_within.rb (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/exception.rb b/activesupport/lib/active_support/core_ext/exception.rb index 0b65af7bf8..2e3965117b 100644 --- a/activesupport/lib/active_support/core_ext/exception.rb +++ b/activesupport/lib/active_support/core_ext/exception.rb @@ -1,25 +1,30 @@ -class Exception - alias :clean_message :message +class Exception # :nodoc: + def clean_message + Pathname.clean_within message + end TraceSubstitutions = [] - FrameworkRegexp = /generated_code|vendor|dispatch|ruby|script\/\w+/ + FrameworkRegexp = /generated|vendor|dispatch|ruby|script\/\w+/ def clean_backtrace backtrace.collect do |line| - TraceSubstitutions.inject(line) do |line, (regexp, sub)| + Pathname.clean_within(TraceSubstitutions.inject(line) do |line, (regexp, sub)| line.gsub regexp, sub - end + end) end end def application_backtrace before_application_frame = true - clean_backtrace.reject do |line| - non_app_frame = !! (line =~ FrameworkRegexp) + trace = clean_backtrace.reject do |line| + non_app_frame = (line =~ FrameworkRegexp) before_application_frame = false unless non_app_frame non_app_frame && ! before_application_frame end + + # If we didn't find any application frames, return an empty app trace. + before_application_frame ? [] : trace end def framework_backtrace diff --git a/activesupport/lib/active_support/core_ext/pathname.rb b/activesupport/lib/active_support/core_ext/pathname.rb new file mode 100644 index 0000000000..9e78c273d9 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/pathname.rb @@ -0,0 +1,7 @@ +require 'pathname' +require File.dirname(__FILE__) + '/pathname/clean_within' + +class Pathname#:nodoc: + extend ActiveSupport::CoreExtensions::Pathname::CleanWithin +end + diff --git a/activesupport/lib/active_support/core_ext/pathname/clean_within.rb b/activesupport/lib/active_support/core_ext/pathname/clean_within.rb new file mode 100644 index 0000000000..ae03e1bc5a --- /dev/null +++ b/activesupport/lib/active_support/core_ext/pathname/clean_within.rb @@ -0,0 +1,14 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Pathname #:nodoc: + module CleanWithin + # Clean the paths contained in the provided string. + def clean_within(string) + string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path| + new(path).cleanpath + end + end + end + end + end +end -- cgit v1.2.3