Sha256: efdda200052ea5fbdb25ce356279386ddcc3be2940595fa63f86bae404d92534

Contents?: true

Size: 698 Bytes

Versions: 7

Compression:

Stored size: 698 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

7 entries across 7 versions & 1 rubygems

Version Path
deprecation_toolkit-2.2.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.1.0 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.0.4 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.0.3 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.0.2 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.0.1 lib/deprecation_toolkit/deprecation_subscriber.rb
deprecation_toolkit-2.0.0 lib/deprecation_toolkit/deprecation_subscriber.rb