Class: Dsu::Validators::EntriesValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Includes:
Support::FieldErrors
Defined in:
lib/dsu/validators/entries_validator.rb

Overview

TODO: I18n.

Constant Summary

Constants included from Support::FieldErrors

Support::FieldErrors::FIELD_DUPLICATE_ERROR, Support::FieldErrors::FIELD_FORMAT_ERROR, Support::FieldErrors::FIELD_TYPE_ERROR

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dsu/validators/entries_validator.rb', line 13

def validate(record)
  unless record.entries.is_a?(Array)
    record.errors.add(:entries, 'is the wrong object type. ' \
                                "\"Array\" was expected, but \"#{record.entries.class}\" was received.")
    return
  end

  return if validate_entry_types record

  validate_unique_entry record
  validate_entries record
end