Class: RuboCop::Cop::Rails::BulkChangeTable::AlterMethodsRecorder
- Inherits:
-
Object
- Object
- RuboCop::Cop::Rails::BulkChangeTable::AlterMethodsRecorder
- Defined in:
- lib/rubocop/cop/rails/bulk_change_table.rb
Overview
Record combinable alter methods and register offensive nodes.
Instance Method Summary collapse
- #flush ⇒ Object
-
#initialize ⇒ AlterMethodsRecorder
constructor
A new instance of AlterMethodsRecorder.
- #offensive_nodes ⇒ Object
- #process(new_node) ⇒ Object
Constructor Details
#initialize ⇒ AlterMethodsRecorder
Returns a new instance of AlterMethodsRecorder.
265 266 267 268 |
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 265 def initialize @nodes = [] @offensive_nodes = [] end |
Instance Method Details
#flush ⇒ Object
284 285 286 287 |
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 284 def flush @offensive_nodes << @nodes.first if @nodes.size > 1 @nodes = [] end |
#offensive_nodes ⇒ Object
289 290 291 292 |
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 289 def offensive_nodes flush @offensive_nodes end |
#process(new_node) ⇒ Object
271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rubocop/cop/rails/bulk_change_table.rb', line 271 def process(new_node) # arguments: [{(sym :table)(str "table")} ...] table_node = new_node.arguments[0] if table_node.is_a? RuboCop::AST::BasicLiteralNode flush unless @nodes.all? do |node| node.arguments[0].value.to_s == table_node.value.to_s end @nodes << new_node else flush end end |