pvincent
2 months ago
4 changed files with 43 additions and 33 deletions
-
1config/environments/development.rb
-
32lib/semantic/dev_loader.rb
-
4lib/semantic/notification_helper.rb
-
39lib/semantic/notification_util.rb
@ -1,4 +0,0 @@ |
|||
module Semantic |
|||
module NotificationHelper |
|||
end |
|||
end |
@ -0,0 +1,39 @@ |
|||
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 |
Write
Preview
Loading…
Cancel
Save
Reference in new issue