Class: RuboCop::Cop::Doctolib::OneOperationPerMigration

Inherits:
Cop
  • Object
show all
Defined in:
lib/rubocop/cop/doctolib/one_operation_per_migration.rb

Overview

Flag ActiveRecord database migrations which contain more than one operation.

Examples:


# bad
def change
  add_column :foos, :bar, :text
  add_column :foos, :qux, :text
end

# good
def change
  add_column :foos, :bar, :text
end

Constant Summary collapse

MSG =
'Use only one operation per migration.'

Instance Method Summary collapse

Instance Method Details

#on_def(node) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/rubocop/cop/doctolib/one_operation_per_migration.rb', line 61

def on_def(node)
  migration_count = 0
  each_child_recursive(node) do |child|
    next unless migration_operation?(child)

    migration_count += 1
    add_offense(node) if migration_count > 1
  end
end