Skip to content

Instantly share code, notes, and snippets.

@inopinatus
Created September 14, 2020 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inopinatus/b53513f72701e4064f418bdbb0b9e0d4 to your computer and use it in GitHub Desktop.
Save inopinatus/b53513f72701e4064f418bdbb0b9e0d4 to your computer and use it in GitHub Desktop.
initializer for determining where callbacks were registered
# 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']
@inopinatus
Copy link
Author

This depends very much on undocumented Rails internals which can change without warning.

This version known to work with Rails 6.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment