class Loga::Railtie::InitializeInstrumentation
Public Class Methods
call()
click to toggle source
# File lib/loga/railtie.rb, line 151 def self.call new.call end
Public Instance Methods
call()
click to toggle source
# File lib/loga/railtie.rb, line 155 def call ensure_subscriptions_attached subscribe_to_action_mailer remove_log_subscriptions end
Private Instance Methods
ensure_subscriptions_attached()
click to toggle source
Ensure LogSubscribers
are attached when available
# File lib/loga/railtie.rb, line 168 def ensure_subscriptions_attached ActionView::Base if defined?(ActionView::Base) ActionController::Base if defined?(ActionController::Base) ActionMailer::Base if defined?(ActionMailer::Base) end
log_subscription_component(subscriber)
click to toggle source
# File lib/loga/railtie.rb, line 182 def log_subscription_component(subscriber) # rubocop:disable CyclomaticComplexity case subscriber when defined?(ActionView::LogSubscriber) && ActionView::LogSubscriber :action_view when defined?(ActionController::LogSubscriber) && ActionController::LogSubscriber :action_controller when defined?(ActionMailer::LogSubscriber) && ActionMailer::LogSubscriber :action_mailer end end
remove_log_subscriptions()
click to toggle source
# File lib/loga/railtie.rb, line 174 def remove_log_subscriptions ActiveSupport::LogSubscriber.log_subscribers.each do |subscriber| component = log_subscription_component(subscriber) unsubscribe(component, subscriber) end end
subscribe_to_action_mailer()
click to toggle source
# File lib/loga/railtie.rb, line 163 def subscribe_to_action_mailer LogSubscribers::ActionMailer.attach_to(:action_mailer) end
unsubscribe(component, subscriber)
click to toggle source
# File lib/loga/railtie.rb, line 193 def unsubscribe(component, subscriber) 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