You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to write a custom cop that detects the usage of update_all or update_column on some specific ActiveRecord models. To make this cop work even for newer models I need to be able to get the list of models when the cop is run.
So I tried running the below code to identify all models in the custom cops' on_new_investigation
module RuboCop
module Cop
class CheckUpdatedAt < Base
ERROR_MSG = 'Using update_all/update_column will not update the updated_at column nor trigger callbacks '.freeze
def on_send(node)
# omitted
end
def on_new_investigation
Rails.application.eager_load!
@models, @associations = [], {}
ActiveRecord::Base.descendants.each do |model_class|
@models << model_class if model_has_method?(model_class, method_name)
end
end
end
end
end
This doesn't work since there is no context of rails classes when executing rubocop. I tried including 'rails' that didn't work either.
Can you help me identify if it's possible to use rails classes like the one mentioned above in on_new_investigation of my custom cop?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I'm trying to write a custom cop that detects the usage of
update_all
orupdate_column
on some specificActiveRecord
models. To make this cop work even for newer models I need to be able to get the list of models when the cop is run.So I tried running the below code to identify all models in the custom cops'
on_new_investigation
This doesn't work since there is no context of rails classes when executing rubocop. I tried including 'rails' that didn't work either.
Can you help me identify if it's possible to use rails classes like the one mentioned above in
on_new_investigation
of my custom cop?Beta Was this translation helpful? Give feedback.
All reactions