Class: Maglev::CollectionValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/maglev/collection_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'app/validators/maglev/collection_validator.rb', line 5

def validate_each(record, attribute, value)
  prefix = attribute.to_s.singularize.humanize

  value.each_with_index do |item, index|
    next if item.valid?

    record.errors.add(
      "#{prefix} ##{index}",
      "is invalid, reason(s): #{clean_item_errors(item)}"
    )
  end
end