Sha256: d28c6fe0cb55867c7122a2f6085c3a505166ede9e6ff58ca97b75ba6740ac251

Contents?: true

Size: 533 Bytes

Versions: 24

Compression:

Stored size: 533 Bytes

Contents

# frozen_string_literal: true

module Maglev
  class CollectionValidator < ActiveModel::EachValidator
    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

    private

    def clean_item_errors(item)
      item.errors.full_messages.join(', ')
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
maglevcms-1.7.3 app/validators/maglev/collection_validator.rb
maglevcms-1.7.2 app/validators/maglev/collection_validator.rb
maglevcms-1.7.1 app/validators/maglev/collection_validator.rb
maglevcms-1.7.0 app/validators/maglev/collection_validator.rb
maglevcms-1.6.1 app/validators/maglev/collection_validator.rb
maglevcms-1.6.0 app/validators/maglev/collection_validator.rb
maglevcms-1.5.1 app/validators/maglev/collection_validator.rb
maglevcms-1.4.0 app/validators/maglev/collection_validator.rb
maglevcms-1.3.0 app/validators/maglev/collection_validator.rb
maglevcms-1.2.2 app/validators/maglev/collection_validator.rb
maglevcms-1.2.1 app/validators/maglev/collection_validator.rb
maglevcms-1.2.0 app/validators/maglev/collection_validator.rb
maglevcms-1.1.7 app/validators/maglev/collection_validator.rb
maglevcms-1.1.6 app/validators/maglev/collection_validator.rb
maglevcms-1.1.5 app/validators/maglev/collection_validator.rb
maglevcms-1.1.4 app/validators/maglev/collection_validator.rb
maglevcms-1.1.3 app/validators/maglev/collection_validator.rb
maglevcms-1.1.2 app/validators/maglev/collection_validator.rb
maglevcms-1.1.1 app/validators/maglev/collection_validator.rb
maglevcms-1.1.0 app/validators/maglev/collection_validator.rb