Skip to content
This repository
Browse code

Eliminate Pathname extensions

  • Loading branch information...
commit bd84b820188daed991756531071137dc7e0876a0 1 parent 727e9dc
Jeremy Kemper authored April 17, 2009
17  activesupport/lib/active_support/core_ext/exception.rb
... ...
@@ -1,13 +1,19 @@
1  
-require 'active_support/core_ext/pathname'
2  
-
3 1
 module ActiveSupport
4 2
   FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError
5 3
 end
6 4
 
7 5
 # TODO: Turn all this into using the BacktraceCleaner.
8 6
 class Exception # :nodoc:
  7
+  # Clean the paths contained in the message.
  8
+  def self.clean_paths(string)
  9
+    require 'pathname' unless defined? Pathname
  10
+    string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
  11
+      Pathname.new(path).cleanpath
  12
+    end
  13
+  end
  14
+
9 15
   def clean_message
10  
-    Pathname.clean_within message
  16
+    Exception.clean_paths(message)
11 17
   end
12 18
 
13 19
   TraceSubstitutions = []
@@ -16,9 +22,10 @@ def clean_message
16 22
 
17 23
   def clean_backtrace
18 24
     backtrace.collect do |line|
19  
-      Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)|
  25
+      substituted = TraceSubstitutions.inject(line) do |result, (regexp, sub)|
20 26
         result.gsub regexp, sub
21  
-      end)
  27
+      end
  28
+      Exception.clean_paths(substituted)
22 29
     end
23 30
   end
24 31
 
5  activesupport/lib/active_support/core_ext/pathname.rb
... ...
@@ -1,5 +0,0 @@
1  
-if defined? Pathname
2  
-  require 'active_support/core_ext/pathname/clean_within'
3  
-else
4  
-  autoload :Pathname, 'active_support/core_ext/pathname/clean_within'
5  
-end
10  activesupport/lib/active_support/core_ext/pathname/clean_within.rb
... ...
@@ -1,10 +0,0 @@
1  
-require 'pathname'
2  
-
3  
-class Pathname
4  
-  # Clean the paths contained in the provided string.
5  
-  def self.clean_within(string)
6  
-    string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
7  
-      new(path).cleanpath
8  
-    end
9  
-  end
10  
-end
10  activesupport/test/core_ext/pathname_test.rb
... ...
@@ -1,10 +0,0 @@
1  
-require 'abstract_unit'
2  
-require 'active_support/core_ext/pathname'
3  
-
4  
-class TestPathname < Test::Unit::TestCase
5  
-  def test_clean_within
6  
-    assert_equal "Hi", Pathname.clean_within("Hi")
7  
-    assert_equal "Hi", Pathname.clean_within("Hi/a/b/../..")
8  
-    assert_equal "Hello\nWorld", Pathname.clean_within("Hello/a/b/../..\na/b/../../World/c/..")
9  
-  end
10  
-end

0 notes on commit bd84b82

Please sign in to comment.
Something went wrong with that request. Please try again.