Sha256: fc5ea4a72cd767a78d385532068a746f81e493b348a7533d72996e31842f523f

Contents?: true

Size: 1.1 KB

Versions: 57

Compression:

Stored size: 1.1 KB

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

      # I don't know why this has to be so complicated, but it is. This code was taken from
      # lograge :/
      def unsubscribe!(component, type)
        subscriber = find(component, type)

        if !subscriber
          raise "We could not find a log subscriber for #{component.inspect} of type #{type.inspect}"
        end

        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

Version data entries

57 entries across 57 versions & 1 rubygems

Version Path
timber-2.6.2 lib/timber/util/active_support_log_subscriber.rb
timber-2.6.1 lib/timber/util/active_support_log_subscriber.rb
timber-2.6.0 lib/timber/util/active_support_log_subscriber.rb
timber-2.6.0.pre.beta2 lib/timber/util/active_support_log_subscriber.rb
timber-2.6.0.pre.beta1 lib/timber/util/active_support_log_subscriber.rb
timber-2.5.1 lib/timber/util/active_support_log_subscriber.rb
timber-2.5.0 lib/timber/util/active_support_log_subscriber.rb
timber-2.4.0 lib/timber/util/active_support_log_subscriber.rb
timber-2.3.4 lib/timber/util/active_support_log_subscriber.rb
timber-2.3.3 lib/timber/util/active_support_log_subscriber.rb
timber-2.3.2 lib/timber/util/active_support_log_subscriber.rb
timber-2.3.1 lib/timber/util/active_support_log_subscriber.rb
timber-2.3.0 lib/timber/util/active_support_log_subscriber.rb
timber-2.2.3 lib/timber/util/active_support_log_subscriber.rb
timber-2.2.2 lib/timber/util/active_support_log_subscriber.rb
timber-2.2.1 lib/timber/util/active_support_log_subscriber.rb
timber-2.2.0 lib/timber/util/active_support_log_subscriber.rb
timber-2.1.10 lib/timber/util/active_support_log_subscriber.rb
timber-2.1.9 lib/timber/util/active_support_log_subscriber.rb
timber-2.1.8 lib/timber/util/active_support_log_subscriber.rb