Class: Airbrake::FilterChain Private
- Inherits:
-
Object
- Object
- Airbrake::FilterChain
- Defined in:
- lib/airbrake-ruby/filter_chain.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
FilterChain represents an ordered array of filters.
A filter is an object that responds to #call (typically a Proc or a class that implements the call method). The #call method must accept exactly one argument: an object to be filtered.
When you add a new filter to the chain, it gets inserted according to its weight. Smaller weight means the filter will be somewhere in the beginning of the array. Larger - in the end. If a filter doesn’t implement weight, the chain assumes it’s equal to 0.
Constant Summary collapse
- DEFAULT_WEIGHT =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
0
Instance Method Summary collapse
-
#add_filter(filter) ⇒ void
private
Adds a filter to the filter chain.
-
#delete_filter(filter_class) ⇒ void
private
Deletes a filter from the the filter chain.
-
#includes?(filter_class) ⇒ Boolean
private
True if the current chain has an instance of the given class, false otherwise.
-
#initialize ⇒ FilterChain
constructor
private
A new instance of FilterChain.
-
#inspect ⇒ String
private
Customized inspect to lessen the amount of clutter.
-
#pretty_print(q) ⇒ String
private
#inspect for PrettyPrint.
-
#refine(notice) ⇒ void
private
Applies all the filters in the filter chain to the given notice.
Constructor Details
#initialize ⇒ FilterChain
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of FilterChain.
40 41 42 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 40 def initialize @filters = [] end |
Instance Method Details
#add_filter(filter) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Adds a filter to the filter chain. Sorts filters by weight.
48 49 50 51 52 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 48 def add_filter(filter) @filters = (@filters << filter).sort_by do |f| f.respond_to?(:weight) ? f.weight : DEFAULT_WEIGHT end.reverse! end |
#delete_filter(filter_class) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Deletes a filter from the the filter chain.
59 60 61 62 63 64 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 59 def delete_filter(filter_class) # rubocop:disable Style/ClassEqualityComparison index = @filters.index { |f| f.class.name == filter_class.name } # rubocop:enable Style/ClassEqualityComparison @filters.delete_at(index) if index end |
#includes?(filter_class) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns true if the current chain has an instance of the given class, false otherwise.
102 103 104 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 102 def includes?(filter_class) filter_classes.include?(filter_class) end |
#inspect ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns customized inspect to lessen the amount of clutter.
81 82 83 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 81 def inspect filter_classes.to_s end |
#pretty_print(q) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns #inspect for PrettyPrint.
86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 86 def pretty_print(q) q.text('[') # Make nesting of the first element consistent on JRuby and MRI. q.nest(2) { q.breakable } if @filters.any? q.nest(2) do q.seplist(@filters) { |f| q.pp(f.class) } end q.text(']') end |
#refine(notice) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Make it work with anything, not only notices
This method returns an undefined value.
Applies all the filters in the filter chain to the given notice. Does not filter ignored notices.
72 73 74 75 76 77 78 |
# File 'lib/airbrake-ruby/filter_chain.rb', line 72 def refine(notice) @filters.each do |filter| break if notice.ignored? filter.call(notice) end end |