Created
September 14, 2020 22:42
-
-
Save inopinatus/b53513f72701e4064f418bdbb0b9e0d4 to your computer and use it in GitHub Desktop.
initializer for determining where callbacks were registered
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# frozen_string_literal: true | |
module CallbackRegistrationTracing | |
module Capture | |
def normalize_callback_params(*args) | |
super.tap do |_, _, options| | |
options[:_caller] = caller(3) | |
end | |
end | |
end | |
module Keep | |
def initialize(name, filter, kind, options, chain_config) | |
@caller = options.delete(:_caller) | |
super | |
end | |
end | |
ActiveRecord::Base.extend Capture | |
ActiveSupport::Callbacks::Callback.prepend Keep | |
end if Rails.env.development? && ENV['CALLBACK_REGISTRATION_TRACING'] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This depends very much on undocumented Rails internals which can change without warning.
This version known to work with Rails 6.0.