Class: Gitlab::Styles::Rubocop::Cop::Migration::AddConcurrentIndex

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
MigrationHelpers
Defined in:
lib/gitlab/styles/rubocop/cop/migration/add_concurrent_index.rb

Overview

Cop that checks if add_concurrent_index is used with up/down methods and not change.

Constant Summary collapse

MSG =
'`add_concurrent_index` is not reversible so you must manually define ' \
'the `up` and `down` methods in your migration class, using `remove_concurrent_index` in `down`'.freeze

Instance Method Summary collapse

Methods included from MigrationHelpers

#in_migration?

Instance Method Details

#method_name(node) ⇒ Object



30
31
32
# File 'lib/gitlab/styles/rubocop/cop/migration/add_concurrent_index.rb', line 30

def method_name(node)
  node.children.first
end

#on_send(node) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab/styles/rubocop/cop/migration/add_concurrent_index.rb', line 16

def on_send(node)
  return unless in_migration?(node)

  name = node.children[1]

  return unless name == :add_concurrent_index

  node.each_ancestor(:def) do |def_node|
    next unless method_name(def_node) == :change

    add_offense(def_node, :name)
  end
end