Sha256: 436d378e813e4fd566447c09ec432976257abee64235d937dc18a974eecbd53e

Contents?: true

Size: 1.21 KB

Versions: 5

Compression:

Stored size: 1.21 KB

Contents

class MultipleDevicesLogger

  module IgnoreExceptions

    extend ActiveSupport::Concern

    def exception_ignored?(exception)
      return false unless exception.is_a?(Exception)
      ignored_exception_classes.any? { |klass| exception.is_a?(klass) } || ignored_exceptions_procs.any? { |proc| proc.call(exception) }
    end

    def ignore_exceptions(*arguments, &block)
      @ignored_exception_class_names ||= []
      @ignored_exceptions_procs ||= []
      @ignored_exceptions_procs << Proc.new(&block) if block_given?
      [arguments].flatten.each do |argument|
        if argument.respond_to?(:call)
          @ignored_exceptions_procs << argument
        else
          klass = argument.is_a?(Class) ? argument : argument.to_s.presence.try(:constantize)
          raise("Invalid exception class: #{argument.inspect}") unless klass.is_a?(Class) && (klass == Exception || (klass < Exception))
          @ignored_exception_class_names << klass.name
        end
      end
      @ignored_exception_class_names.uniq!
      nil
    end

    def ignored_exception_classes
      (@ignored_exception_class_names || []).map(&:constantize)
    end

    def ignored_exceptions_procs
      @ignored_exceptions_procs || []
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
multiple_devices_logger-3.2.0 lib/multiple_devices_logger/ignore_exceptions.rb
multiple_devices_logger-3.1.3 lib/multiple_devices_logger/ignore_exceptions.rb
multiple_devices_logger-3.1.2 lib/multiple_devices_logger/ignore_exceptions.rb
multiple_devices_logger-3.1.1 lib/multiple_devices_logger/ignore_exceptions.rb
multiple_devices_logger-3.1.0 lib/multiple_devices_logger/ignore_exceptions.rb