Skip to content

Commit 89b0a8c

Browse files
authored
Merge pull request rails#49653 from Earlopain/add_filter-example
Better example for backtrace filter add_filter
2 parents 9483a19 + 1c7f9b0 commit 89b0a8c

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

activesupport/lib/active_support/backtrace_cleaner.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ module ActiveSupport
1717
# can focus on the rest.
1818
#
1919
# bc = ActiveSupport::BacktraceCleaner.new
20-
# bc.add_filter { |line| line.gsub(Rails.root.to_s, '') } # strip the Rails.root prefix
20+
# root = "#{Rails.root}/"
21+
# bc.add_filter { |line| line.start_with?(root) ? line.from(root.size) : line } # strip the Rails.root prefix
2122
# bc.add_silencer { |line| /puma|rubygems/.match?(line) } # skip any lines from puma or rubygems
2223
# bc.clean(exception.backtrace) # perform the cleanup
2324
#
@@ -75,8 +76,9 @@ def clean_frame(frame, kind = :silent)
7576
# Adds a filter from the block provided. Each line in the backtrace will be
7677
# mapped against this filter.
7778
#
78-
# # Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
79-
# backtrace_cleaner.add_filter { |line| line.gsub(Rails.root.to_s, '') }
79+
# # Will turn "/my/rails/root/app/models/person.rb" into "app/models/person.rb"
80+
# root = "#{Rails.root}/"
81+
# backtrace_cleaner.add_filter { |line| line.start_with?(root) ? line.from(root.size) : line }
8082
def add_filter(&block)
8183
@filters << block
8284
end

0 commit comments

Comments
 (0)