Class: CountValidator
- Inherits:
-
ActiveModel::Validations::LengthValidator
- Object
- ActiveModel::Validations::LengthValidator
- CountValidator
- Defined in:
- app/validators/count_validator.rb
Constant Summary collapse
- MESSAGES =
{ :wrong_length => :count_invalid, :too_short => :count_greater_than_or_equal_to, :too_long => :count_less_than_or_equal_to }.freeze
Instance Method Summary collapse
-
#initialize(options) ⇒ CountValidator
constructor
A new instance of CountValidator.
- #validate_each(record, attribute, value) ⇒ Object
Constructor Details
#initialize(options) ⇒ CountValidator
Returns a new instance of CountValidator.
8 9 10 11 |
# File 'app/validators/count_validator.rb', line 8 def initialize() = .reverse_merge(MESSAGES) super end |
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
13 14 15 16 |
# File 'app/validators/count_validator.rb', line 13 def validate_each(record, attribute, value) existing_records = record.send(attribute).reject(&:marked_for_destruction?) super(record, attribute, existing_records) end |