Eliminate Pathname extensions

This commit is contained in:
Jeremy Kemper
2009-04-17 21:49:57 -07:00
parent 727e9dc18a
commit bd84b82018
4 changed files with 12 additions and 30 deletions

View File

@@ -1,13 +1,19 @@
require 'active_support/core_ext/pathname'
module ActiveSupport
FrozenObjectError = RUBY_VERSION < '1.9' ? TypeError : RuntimeError
end
# TODO: Turn all this into using the BacktraceCleaner.
class Exception # :nodoc:
# Clean the paths contained in the message.
def self.clean_paths(string)
require 'pathname' unless defined? Pathname
string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
Pathname.new(path).cleanpath
end
end
def clean_message
Pathname.clean_within message
Exception.clean_paths(message)
end
TraceSubstitutions = []
@@ -16,9 +22,10 @@ class Exception # :nodoc:
def clean_backtrace
backtrace.collect do |line|
Pathname.clean_within(TraceSubstitutions.inject(line) do |result, (regexp, sub)|
substituted = TraceSubstitutions.inject(line) do |result, (regexp, sub)|
result.gsub regexp, sub
end)
end
Exception.clean_paths(substituted)
end
end

View File

@@ -1,5 +0,0 @@
if defined? Pathname
require 'active_support/core_ext/pathname/clean_within'
else
autoload :Pathname, 'active_support/core_ext/pathname/clean_within'
end

View File

@@ -1,10 +0,0 @@
require 'pathname'
class Pathname
# Clean the paths contained in the provided string.
def self.clean_within(string)
string.gsub(%r{[\w. ]+(/[\w. ]+)+(\.rb)?(\b|$)}) do |path|
new(path).cleanpath
end
end
end

View File

@@ -1,10 +0,0 @@
require 'abstract_unit'
require 'active_support/core_ext/pathname'
class TestPathname < Test::Unit::TestCase
def test_clean_within
assert_equal "Hi", Pathname.clean_within("Hi")
assert_equal "Hi", Pathname.clean_within("Hi/a/b/../..")
assert_equal "Hello\nWorld", Pathname.clean_within("Hello/a/b/../..\na/b/../../World/c/..")
end
end