Class: ExceptionHandling::ExceptionFilters::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_handling.rb

Instance Method Summary collapse

Constructor Details

#initialize(filter_name, regexes) ⇒ Filter



504
505
506
507
508
509
510
511
512
# File 'lib/exception_handling.rb', line 504

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



514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'lib/exception_handling.rb', line 514

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