~michaelforrest/use-case-mapper/trunk

« back to all changes in this revision

Viewing changes to vendor/rails/railties/lib/rails/backtrace_cleaner.rb

  • Committer: Richard Lee (Canonical)
  • Date: 2010-10-15 15:17:58 UTC
  • mfrom: (190.1.3 use-case-mapper)
  • Revision ID: richard.lee@canonical.com-20101015151758-wcvmfxrexsongf9d
Merge

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
module Rails
2
 
  class BacktraceCleaner < ActiveSupport::BacktraceCleaner
3
 
    ERB_METHOD_SIG = /:in `_run_erb_.*/
4
 
 
5
 
    RAILS_GEMS   = %w( actionpack activerecord actionmailer activesupport activeresource rails )
6
 
 
7
 
    VENDOR_DIRS  = %w( vendor/rails )
8
 
    SERVER_DIRS  = %w( lib/mongrel bin/mongrel
9
 
                       lib/passenger bin/passenger-spawn-server
10
 
                       lib/rack )
11
 
    RAILS_NOISE  = %w( script/server )
12
 
    RUBY_NOISE   = %w( rubygems/custom_require benchmark.rb )
13
 
 
14
 
    ALL_NOISE    = VENDOR_DIRS + SERVER_DIRS + RAILS_NOISE + RUBY_NOISE
15
 
 
16
 
    def initialize
17
 
      super
18
 
      add_filter   { |line| line.sub("#{RAILS_ROOT}/", '') }
19
 
      add_filter   { |line| line.sub(ERB_METHOD_SIG, '') }
20
 
      add_filter   { |line| line.sub('./', '/') } # for tests
21
 
 
22
 
      add_gem_filters
23
 
 
24
 
      add_silencer { |line| ALL_NOISE.any? { |dir| line.include?(dir) } }
25
 
      add_silencer { |line| RAILS_GEMS.any? { |gem| line =~ /^#{gem} / } }
26
 
      add_silencer { |line| line =~ %r(vendor/plugins/[^\/]+/lib) }
27
 
    end
28
 
    
29
 
    
30
 
    private
31
 
      def add_gem_filters
32
 
        Gem.path.each do |path|
33
 
          # http://gist.github.com/30430
34
 
          add_filter { |line| line.sub(/(#{path})\/gems\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) \4')}
35
 
        end
36
 
 
37
 
        vendor_gems_path = Rails::GemDependency.unpacked_path.sub("#{RAILS_ROOT}/",'')
38
 
        add_filter { |line| line.sub(/(#{vendor_gems_path})\/([a-z]+)-([0-9.]+)\/(.*)/, '\2 (\3) [v] \4')}
39
 
      end
40
 
  end
41
 
 
42
 
  # For installing the BacktraceCleaner in the test/unit
43
 
  module BacktraceFilterForTestUnit #:nodoc:
44
 
    def self.included(klass)
45
 
      klass.send :alias_method_chain, :filter_backtrace, :cleaning
46
 
    end
47
 
 
48
 
    def filter_backtrace_with_cleaning(backtrace, prefix=nil)
49
 
      backtrace = filter_backtrace_without_cleaning(backtrace, prefix)
50
 
      backtrace = backtrace.first.split("\n") if backtrace.size == 1
51
 
      Rails.backtrace_cleaner.clean(backtrace)
52
 
    end
53
 
  end
54
 
end