Created
April 28, 2021 04:22
-
-
Save ibanez270dx/4de590b64c0b657138f828103ef0fee7 to your computer and use it in GitHub Desktop.
Debug calls to ActiveRecord::Persistence::ClassMethods.create
This file contains hidden or 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
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
after_create -> do | |
$caller_counter ||= 0 | |
$caller_counter += 1 | |
message = "call ##{$caller_counter}:".bold | |
message += caller.select{ |trace| trace.include?(Rails.root.to_s) }.map.with_index{ |trace, index| "#{index+1}. #{trace}" }.join("\n") | |
message += """created #{self.class.class_name} with id=`#{id}'\n\n""".send(%w(blue cyan yellow magenta white green red).sample).bold | |
puts message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment