2018-11-20 20:47:30 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
# Cop that blacklists the use of `destroy_all`.
|
2022-10-11 01:57:18 +05:30
|
|
|
class DestroyAll < RuboCop::Cop::Base
|
2018-11-20 20:47:30 +05:30
|
|
|
MSG = 'Use `delete_all` instead of `destroy_all`. ' \
|
|
|
|
'`destroy_all` will load the rows into memory, then execute a ' \
|
|
|
|
'`DELETE` for every individual row.'
|
|
|
|
|
|
|
|
def_node_matcher :destroy_all?, <<~PATTERN
|
|
|
|
(send {send ivar lvar const} :destroy_all ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless destroy_all?(node)
|
|
|
|
|
2022-10-11 01:57:18 +05:30
|
|
|
add_offense(node)
|
2018-11-20 20:47:30 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|