Class: ExceptionHandling::ExceptionFilters::Filter
- Inherits:
-
Object
- Object
- ExceptionHandling::ExceptionFilters::Filter
- Defined in:
- lib/exception_handling.rb
Instance Method Summary collapse
-
#initialize(filter_name, regexes) ⇒ Filter
constructor
A new instance of Filter.
- #match?(exception_data) ⇒ Boolean
Constructor Details
#initialize(filter_name, regexes) ⇒ Filter
Returns a new instance of Filter.
600 601 602 603 604 605 606 607 608 |
# File 'lib/exception_handling.rb', line 600 def initialize filter_name, regexes @regexes = Hash[ regexes.map do |section, regex| section = section.to_sym raise "Unknown section: #{section}" unless section == :error || section.in?( ExceptionHandling::SECTIONS ) [section, (Regexp.new(regex, 'i') unless regex.blank?)] end ] raise "Filter #{filter_name} has all blank regexes: #{regexes.inspect}" if @regexes.all? { |section, regex| regex.nil? } end |
Instance Method Details
#match?(exception_data) ⇒ Boolean
610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/exception_handling.rb', line 610 def match?(exception_data) @regexes.all? do |section, regex| regex.nil? || case exception_data[section.to_s] when String regex =~ exception_data[section] when Array exception_data[section].any? { |row| row =~ regex } when Hash exception_data[section] && exception_data[section][:to_s] =~ regex when NilClass false else raise "Unexpected class #{exception_data[section].class.name}" end end end |