blob: 3a1f3b64d75e9097aae997568ddb367b800a634b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# frozen_string_literal: true
require_relative '../../migration_helpers'
module RuboCop
module Cop
module Migration
# Cop that checks that no background batched migration helpers are called by regular migrations.
class BatchMigrationsPostOnly < RuboCop::Cop::Base
include MigrationHelpers
MSG = "This method must only be used in post-deployment migrations."
FORBIDDEN_METHODS = %w[
ensure_batched_background_migration_is_finished
queue_batched_background_migration
delete_batched_background_migration
finalize_batched_background_migration
].freeze
SYMBOLIZED_MATCHER = FORBIDDEN_METHODS.map { |w| ":#{w}" }.join(' | ')
def_node_matcher :on_forbidden_method, <<~PATTERN
(send nil? {#{SYMBOLIZED_MATCHER}} ...)
PATTERN
def on_send(node)
on_forbidden_method(node) do
break if in_post_deployment_migration?(node)
add_offense(node, message: MSG)
end
end
end
end
end
end
|