|
|
@ -3,15 +3,21 @@ module Semantic |
|
|
|
class DevLoader |
|
|
|
def initialize(session_key) |
|
|
|
@session_key = session_key |
|
|
|
@subscribers = {} |
|
|
|
|
|
|
|
RailsSemanticLogger::ActionController::LogSubscriber.logger.level = :fatal # useful for remanent Rack::Log started |
|
|
|
|
|
|
|
launch |
|
|
|
end |
|
|
|
|
|
|
|
def launch |
|
|
|
once_and_reload do |
|
|
|
append_ansi_formatter |
|
|
|
|
|
|
|
Semantic::NotificationUtil.clear_subscribers(/\.action_controller$/) |
|
|
|
Semantic::NotificationUtil.clear_subscribers(/\.action_view$/) |
|
|
|
|
|
|
|
append_ansi_formatter |
|
|
|
reset_subscribers |
|
|
|
|
|
|
|
register_action_controller |
|
|
|
register_action_view |
|
|
|
end |
|
|
@ -51,17 +57,19 @@ module Semantic |
|
|
|
end |
|
|
|
|
|
|
|
def register_hook(sub_instance, hook, method = hook) |
|
|
|
@subscribers << ActiveSupport::Notifications.subscribe("#{hook}.#{sub_instance.event_group}") do |event| |
|
|
|
@subscribers[sub_instance.class] ||= [] |
|
|
|
@subscribers[sub_instance.class] << ActiveSupport::Notifications.subscribe("#{hook}.#{sub_instance.event_group}") do |event| |
|
|
|
sub_instance.send(method, event) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
def reset_subscribers |
|
|
|
if defined?(@subscribers) |
|
|
|
@subscribers.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
@subscribers.clear |
|
|
|
else |
|
|
|
@subscribers = [] |
|
|
|
return if @subscribers.empty? |
|
|
|
|
|
|
|
@subscribers.each_pair do |clazz, subs| |
|
|
|
# puts "reset #{subs.size} subscribers for class <#{clazz}>" |
|
|
|
subs.each { |sub| ActiveSupport::Notifications.unsubscribe(sub) } |
|
|
|
subs.clear |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|