Class: RuboCop::Cop::Rails::ThreeStateBooleanColumn
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rails::ThreeStateBooleanColumn
- Defined in:
- lib/rubocop/cop/rails/three_state_boolean_column.rb
Overview
Enforces that boolean columns are created with default values (‘false` or `true`) and `NOT NULL` constraint.
Constant Summary collapse
- MSG =
'Boolean columns should always have a default value and a `NOT NULL` constraint.'
- RESTRICT_ON_SEND =
%i[add_column column boolean].freeze
Instance Method Summary collapse
Instance Method Details
#on_send(node) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/rails/three_state_boolean_column.rb', line 41 def on_send(node) three_state_boolean?(node) do |column_node, | = .first return if () def_node = node.each_ancestor(:def, :defs).first table_node = table_node(node) return if def_node && (table_node.nil? || change_column_null?(def_node, table_node, column_node)) add_offense(node) end end |