Class: Amount::ActiveRecord::AmountValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- Amount::ActiveRecord::AmountValidator
- Defined in:
- lib/amount/active_record/amount_validator.rb
Overview
Validates model-level business rules for ‘has_amount` attributes.
Structural integrity is still handled by ‘has_amount` itself. This validator adds declarative Rails validations such as symbol checks and comparison constraints.
Constant Summary collapse
- COMPARATORS =
{ greater_than: :>, greater_than_or_equal_to: :>=, less_than: :<, less_than_or_equal_to: :<= }.freeze
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/amount/active_record/amount_validator.rb', line 30 def validate_each(record, attribute, value) return if pending_assignment_error?(record, attribute) return if value.nil? validate_amount_instance(record, attribute, value) validate_symbol(record, attribute, value) validate_comparators(record, attribute, value) end |