Sha256: fad537e7831cff0d48033aef9a3d0a4d8f47584fa23307a4890300e68a9e1b4a

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module Isolator
  module Adapters
    # Used as a "template" for adapters
    module Base
      attr_accessor :exception_class, :exception_message

      def disable!
        @disabled = true
      end

      def enable!
        @disabled = false
      end

      def enabled?
        !disabled?
      end

      def disabled?
        @disabled == true
      end

      def notify(backtrace, *args)
        return unless notify?(*args)
        Isolator.notify(exception: build_exception, backtrace: backtrace)
      end

      def notify?(*args)
        enabled? && Isolator.enabled? && Isolator.within_transaction? && !ignored?(*args)
      end

      def ignore_if
        ignores << Proc.new
      end

      def ignores
        @ignores ||= []
      end

      def ignored?(*args)
        ignores.any? { |block| block.call(*args) }
      end

      private

      def build_exception
        klass = exception_class || Isolator::UnsafeOperationError
        klass.new(exception_message)
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
isolator-0.5.0 lib/isolator/adapters/base.rb
isolator-0.4.0 lib/isolator/adapters/base.rb
isolator-0.3.0 lib/isolator/adapters/base.rb
isolator-0.2.2 lib/isolator/adapters/base.rb
isolator-0.2.1 lib/isolator/adapters/base.rb
isolator-0.2.0 lib/isolator/adapters/base.rb
isolator-0.1.1 lib/isolator/adapters/base.rb
isolator-0.1.0 lib/isolator/adapters/base.rb