Class: Coaster::BacktraceCleaner
- Defined in:
- lib/coaster/backtrace_cleaner.rb
Instance Attribute Summary collapse
-
#least ⇒ Object
Returns the value of attribute least.
Instance Method Summary collapse
-
#add_filter(&block) ⇒ Object
Adds a filter from the block provided.
-
#add_silencer(&block) ⇒ Object
Adds a silencer from the block provided.
-
#clean(backtrace, kind = :silent) ⇒ Object
(also: #filter)
Returns the backtrace after all filters and silencers have been run against it.
-
#initialize ⇒ BacktraceCleaner
constructor
A new instance of BacktraceCleaner.
-
#remove_filters! ⇒ Object
Removes all filters, but leaves in the silencers.
-
#remove_silencers! ⇒ Object
Removes all silencers, but leaves in the filters.
Constructor Details
#initialize ⇒ BacktraceCleaner
4 5 6 7 |
# File 'lib/coaster/backtrace_cleaner.rb', line 4 def initialize @filters, @silencers = [], [] @least = 10 end |
Instance Attribute Details
#least ⇒ Object
Returns the value of attribute least.
2 3 4 |
# File 'lib/coaster/backtrace_cleaner.rb', line 2 def least @least end |
Instance Method Details
#add_filter(&block) ⇒ Object
Adds a filter from the block provided. Each line in the backtrace will be mapped against this filter.
# Will turn "/my/rails/root/app/models/person.rb" into "/app/models/person.rb"
backtrace_cleaner.add_filter { |line| line.gsub(Rails.root, '') }
30 31 32 |
# File 'lib/coaster/backtrace_cleaner.rb', line 30 def add_filter(&block) @filters << block end |
#add_silencer(&block) ⇒ Object
Adds a silencer from the block provided. If the silencer returns true for a given line, it will be excluded from the clean backtrace.
# Will reject all lines that include the word "mongrel", like "/gems/mongrel/server.rb" or "/app/my_mongrel_server/rb"
backtrace_cleaner.add_silencer { |line| line =~ /mongrel/ }
39 40 41 |
# File 'lib/coaster/backtrace_cleaner.rb', line 39 def add_silencer(&block) @silencers << block end |
#clean(backtrace, kind = :silent) ⇒ Object Also known as: filter
Returns the backtrace after all filters and silencers have been run against it. Filters run first, then silencers.
11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/coaster/backtrace_cleaner.rb', line 11 def clean(backtrace, kind = :silent) filtered = filter_backtrace(backtrace) case kind when :silent silence(filtered) when :noise noise(filtered) else filtered end end |
#remove_filters! ⇒ Object
Removes all filters, but leaves in the silencers. Useful if you suddenly need to see entire filepaths in the backtrace that you had already filtered out.
53 54 55 |
# File 'lib/coaster/backtrace_cleaner.rb', line 53 def remove_filters! @filters = [] end |
#remove_silencers! ⇒ Object
Removes all silencers, but leaves in the filters. Useful if your context of debugging suddenly expands as you suspect a bug in one of the libraries you use.
46 47 48 |
# File 'lib/coaster/backtrace_cleaner.rb', line 46 def remove_silencers! @silencers = [] end |