You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

39 lines
1.5 KiB

module Semantic
module NotificationUtil
class << self
# pattern could be either a string 'start_processing.action_controller' or a regex /\.action_controller$/
# FIXME: weird behaviour, order impact!!!!
# For instance:
# OK
# NotificationUtil.clear_subscribers(/\.action_controller$/)
# NotificationUtil.clear_subscribers(/\.action_view$/)
# NOPE
# NotificationUtil.clear_subscribers(/\.action_view$/)
# NotificationUtil.clear_subscribers(/\.action_controller$/)
def clear_subscribers(pattern)
ActiveSupport::LogSubscriber.subscribers.each { |sub| unattach(sub, pattern) }
end
private
def subscriber_patterns(subscriber)
subscriber.patterns.respond_to?(:keys) ? subscriber.patterns.keys : subscriber.patterns
end
def unattach(subscriber, pattern)
subscriber_patterns(subscriber).each do |sub_pattern|
ActiveSupport::Notifications.notifier.listeners_for(sub_pattern).each do |sub|
next unless sub.instance_variable_get(:@delegate) == subscriber
next unless pattern.match(sub_pattern)
puts "FOUND subscriber=#{subscriber} for sub_pattern=#{sub_pattern} with logger #{subscriber.logger.name}"
puts subscriber.class.module_parent.const_source_location(subscriber.class.to_s)&.first
ActiveSupport::Notifications.unsubscribe(sub)
end
end
# ActiveSupport::LogSubscriber.subscribers.delete(subscriber)
end
end
end
end