Class: PGTrunk::AllItemsValidValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/pg_trunk/core/validators/all_items_valid_validator.rb

Overview

Ensure that all items in the array are valid

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
# File 'lib/pg_trunk/core/validators/all_items_valid_validator.rb', line 6

def validate_each(record, attribute, value)
  Array.wrap(value).each.with_index.map do |item, index|
    item.errors.messages.each do |name, list|
      list.each do |message|
        record.errors.add :base, "#{attribute}[#{index}]: #{name} #{message}"
      end
    end
  end
end