Class: HashieModel::AssociatedValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- HashieModel::AssociatedValidator
- Defined in:
- lib/hashie_model/associated_validator.rb
Instance Method Summary collapse
Instance Method Details
#validate_each(record, attribute, value) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/hashie_model/associated_validator.rb', line 3 def validate_each(record, attribute, value) collection = value.is_a?(Array) ? value : [value] invalid_elements = collection.select { |e| e && !e.valid? } if invalid_elements.present? first_error = invalid_elements.first.errors record.errors.add(attribute, first_error, .merge(value: value)) end end |