Sha256: 5705b0e8a2c5312c3bc2b206bea6a5e34ee0bc109e8598ec8a8390e0296a0f34

Contents?: true

Size: 696 Bytes

Versions: 8

Compression:

Stored size: 696 Bytes

Contents

# frozen_string_literal: true

require "active_support/subscriber"

module DeprecationToolkit
  class DeprecationSubscriber < ActiveSupport::Subscriber
    def self.already_attached?
      notifier != nil
    end

    def deprecation(event)
      message = event.payload[:message]

      Collector.collect(message) unless deprecation_allowed?(event.payload)
    end

    private

    def deprecation_allowed?(payload)
      allowed_deprecations, procs = Configuration.allowed_deprecations.partition { |el| el.is_a?(Regexp) }

      allowed_deprecations.any? { |regex| regex =~ payload[:message] } ||
      procs.any? { |proc| proc.call(payload[:message], payload[:callstack]) }
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
deprecation_toolkit-1.5.1 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.5.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.4.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.3.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.2.2 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.2.1 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.2.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-1.1.0 lib/deprecation_toolkit/deprecation_subscriber.rb