Class: RuboCop::Cop::Gusto::IgnoredColumnsAssignment
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Gusto::IgnoredColumnsAssignment
- Defined in:
- lib/rubocop/cop/gusto/ignored_columns_assignment.rb
Overview
Enforces proper usage of ‘ignored_columns` assignment
This cop ensures that ‘ignored_columns` is assigned using `+=` with an array instead of direct assignment, which will overwrite the existing list of ignored columns for the model, or overwrite the list it should inherit in the case of single table inheritance.
Constant Summary collapse
- MSG =
'Use `+=` with an array for `ignored_columns` assignment instead of direct assignment.'- RESTRICT_ON_SEND =
%i(ignored_columns=).freeze
Instance Method Summary collapse
Instance Method Details
#ignored_columns_direct_assignment?(node) ⇒ Object
30 31 32 |
# File 'lib/rubocop/cop/gusto/ignored_columns_assignment.rb', line 30 def_node_matcher :ignored_columns_direct_assignment?, <<~PATTERN (send (self) :ignored_columns= _) PATTERN |
#on_send(node) ⇒ Object
34 35 36 37 38 |
# File 'lib/rubocop/cop/gusto/ignored_columns_assignment.rb', line 34 def on_send(node) if ignored_columns_direct_assignment?(node) add_offense(node.loc.selector) end end |