Class: ActiveModel::EachValidator
- Inherits:
-
Object
- Object
- ActiveModel::EachValidator
- Defined in:
- lib/validates_serialized/each_validator.rb
Overview
Extending ActiveModel’s EachValidator to add validate_each_in_array
Direct Known Subclasses
Instance Method Summary collapse
-
#validate_each_in_array(record) ⇒ Object
Performs validation on the supplied record.
Instance Method Details
#validate_each_in_array(record) ⇒ Object
Performs validation on the supplied record. By default this will call validates_each to determine validity therefore subclasses should override validates_each with validation logic.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/validates_serialized/each_validator.rb', line 9 def validate_each_in_array(record) attributes.each do |attribute| array = record.read_attribute_for_validation(attribute) raise TypeError, "#{array} is not an array" unless array.is_a?(Array) array.each_with_index do |value, index| next if (value.nil? && [:allow_nil]) || (value.blank? && [:allow_blank]) validate_each(record, :"#{attribute}[#{index}]", value) end end end |