Class: RuboCop::Cop::Rails::BulkChangeTable::AlterMethodsRecorder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubocop/cop/rails/bulk_change_table.rb

Overview

Record combinable alter methods and register offensive nodes.

Instance Method Summary collapse

Constructor Details

#initializeAlterMethodsRecorder

Returns a new instance of AlterMethodsRecorder.



247
248
249
250
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 247

def initialize
  @nodes = []
  @offensive_nodes = []
end

Instance Method Details

#flushObject



260
261
262
263
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 260

def flush
  @offensive_nodes << @nodes.first if @nodes.size > 1
  @nodes = []
end

#offensive_nodesObject



265
266
267
268
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 265

def offensive_nodes
  flush
  @offensive_nodes
end

#process(new_node) ⇒ Object

Parameters:



253
254
255
256
257
258
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 253

def process(new_node)
  # arguments: [(sym :table) ...]
  table_name = new_node.arguments[0]
  flush unless @nodes.all? { |node| node.arguments[0] == table_name }
  @nodes << new_node
end