Class: DatabaseConsistency::Comparators::PresenceComparator
- Inherits:
-
BaseComparator
- Object
- BaseComparator
- DatabaseConsistency::Comparators::PresenceComparator
- Defined in:
- lib/database_consistency/comparators/presence_comparator.rb
Overview
The comparator class for {ActiveModel{ActiveModel::Validations{ActiveModel::Validations::PresenceValidator}
Constant Summary collapse
- WEAK_OPTIONS =
%i[allow_nil allow_blank if unless].freeze
- CONSTRAINT_MISSING =
Message templates
'should be required in the database'.freeze
- POSSIBLE_NULL =
'is required but possible null value insert'.freeze
Instance Attribute Summary
Attributes inherited from BaseComparator
Instance Method Summary collapse
-
#compare ⇒ Object
Table of possible statuses | allow_nil/allow_blank/if/unless | database | status | | ——————————- | ——– | —— | | at least one provided | required | fail | | at least one provided | optional | ok | | all missed | required | ok | | all missed | optional | fail |.
Methods inherited from BaseComparator
Constructor Details
This class inherits a constructor from DatabaseConsistency::Comparators::BaseComparator
Instance Method Details
#compare ⇒ Object
Table of possible statuses | allow_nil/allow_blank/if/unless | database | status | | ——————————- | ——– | —— | | at least one provided | required | fail | | at least one provided | optional | ok | | all missed | required | ok | | all missed | optional | fail |
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/database_consistency/comparators/presence_comparator.rb', line 17 def compare can_be_null = column.null has_weak_option = validator..slice(*WEAK_OPTIONS).any? if can_be_null == has_weak_option result(:ok, ) elsif can_be_null result(:fail, (CONSTRAINT_MISSING)) else result(:fail, (POSSIBLE_NULL)) end end |