Sha256: f6b7c81a4139e3bda6f6db6d486bc37ddfb9da677ee5a2b9141c67634684d107

Contents?: true

Size: 918 Bytes

Versions: 30

Compression:

Stored size: 918 Bytes

Contents

module Timber
  module Util
    # @private
    module ActiveSupportLogSubscriber
      extend self

      def find(component, type)
        ActiveSupport::LogSubscriber.log_subscribers.find do |subscriber|
          subscriber.class == type
        end
      end

      def subscribed?(component, type)
        !find(component, type).nil?
      end

      def unsubscribe(component, type)
        subscriber = find(component, type)

        if subscriber
          events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
          events.each do |event|
            ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
              if listener.instance_variable_get('@delegate') == subscriber
                ActiveSupport::Notifications.unsubscribe listener
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 2 rubygems

Version Path
timber-1.1.14 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.13 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.12 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.11 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.10 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.9 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.8 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.7 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.6 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.5 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.4 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.3 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.2 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.1 lib/timber/util/active_support_log_subscriber.rb
timber-1.1.0 lib/timber/util/active_support_log_subscriber.rb
timber-1.0.13 lib/timber/util/active_support_log_subscriber.rb
timber-1.0.12 lib/timber/util/active_support_log_subscriber.rb
timber-1.0.11 lib/timber/util/active_support_log_subscriber.rb
timber-1.0.10 lib/timber/util/active_support_log_subscriber.rb
timber-1.0.9 lib/timber/util/active_support_log_subscriber.rb