Skip to content

Instantly share code, notes, and snippets.

@ibanez270dx
Created April 28, 2021 04:22
Show Gist options
  • Save ibanez270dx/4de590b64c0b657138f828103ef0fee7 to your computer and use it in GitHub Desktop.
Save ibanez270dx/4de590b64c0b657138f828103ef0fee7 to your computer and use it in GitHub Desktop.
Debug calls to ActiveRecord::Persistence::ClassMethods.create
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