Class: Logcraft::Rails::LogSubscriptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/logcraft/rails/log_subscription_handler.rb

Class Method Summary collapse

Class Method Details

.attach(subscriber_class, namespace) ⇒ Object



26
27
28
# File 'lib/logcraft/rails/log_subscription_handler.rb', line 26

def attach(subscriber_class, namespace)
  subscriber_class.attach_to namespace
end

.detach(subscriber_class, namespace) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/logcraft/rails/log_subscription_handler.rb', line 9

def detach(subscriber_class, namespace)
  case ::Rails::VERSION::MAJOR
  when 5
    subscriber = ::ActiveSupport::LogSubscriber.log_subscribers.find { |subscriber| subscriber.is_a? subscriber_class }
    return unless subscriber

    subscriber.patterns.each do |pattern|
      ::ActiveSupport::Notifications.notifier.listeners_for(pattern).each do |listener|
        ::ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate').is_a? subscriber_class
      end
    end

  else
    subscriber_class.detach_from namespace
  end
end