Class: Rails::BacktraceCleaner

Inherits:
ActiveSupport::BacktraceCleaner
  • Object
show all
Defined in:
lib/rails/backtrace_cleaner.rb

Overview

:nodoc:

Constant Summary collapse

APP_DIRS_PATTERN =
/\A(?:\.\/)?(?:app|config|lib|test|\(\w+(?:-\w+)*\))/
RENDER_TEMPLATE_PATTERN =
/:in [`'].*_\w+_{2,3}\d+_\d+'/

Instance Method Summary collapse

Constructor Details

#initializeBacktraceCleaner

Returns a new instance of BacktraceCleaner.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rails/backtrace_cleaner.rb', line 11

def initialize
  super
  add_filter do |line|
    # We may be called before Rails.root is assigned.
    # When that happens we fallback to not truncating.
    @root ||= Rails.root && "#{Rails.root}/"
    @root && line.start_with?(@root) ? line.from(@root.size) : line
  end
  add_filter do |line|
    if RENDER_TEMPLATE_PATTERN.match?(line)
      line.sub(RENDER_TEMPLATE_PATTERN, "")
    else
      line
    end
  end
  add_silencer { |line| !APP_DIRS_PATTERN.match?(line) }
end

Instance Method Details

#clean(backtrace, kind = :silent) ⇒ Object Also known as: filter



29
30
31
32
33
# File 'lib/rails/backtrace_cleaner.rb', line 29

def clean(backtrace, kind = :silent)
  return backtrace if ENV["BACKTRACE"]

  super(backtrace, kind)
end

#clean_frame(frame, kind = :silent) ⇒ Object



36
37
38
39
40
# File 'lib/rails/backtrace_cleaner.rb', line 36

def clean_frame(frame, kind = :silent)
  return frame if ENV["BACKTRACE"]

  super(frame, kind)
end