Skip to content

Instantly share code, notes, and snippets.

@yorickpeterse
Created December 14, 2015 16:01
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 yorickpeterse/0434416575e399649100 to your computer and use it in GitHub Desktop.
Save yorickpeterse/0434416575e399649100 to your computer and use it in GitHub Desktop.
models = Rails.root.join('app', 'models').to_s
ar_regex = /
i?where # where, iwhere
| find(_by)?
| pluck
| select\((:|\[) # select(:id), select([:foo, :bar])
| reorder
| exists\?
| update(_attributes|_all)? # update, update_attributes, update_all
| save
| destroy
| create
| joins
| unscoped
| order(_by)? # order, order_by
/x
ActiveRecord::Base.subclasses.each do |klass|
klass.public_methods(false).each do |name|
method = klass.public_method(name)
source = method.source_location
if source and source[0].start_with?(models) and method.source =~ ar_regex
config.instrument_method(klass, name)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment