Class: Dsu::Validators::ProjectNameValidator

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

Overview

TODO: I18n.

Constant Summary

Constants included from Support::ShortString

Support::ShortString::SHORT_STRING_MAX_COUNT

Constants included from Support::FieldErrors

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

Instance Method Summary collapse

Methods included from Support::ShortString

short_string

Instance Method Details

#validate(record) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/dsu/validators/project_name_validator.rb', line 14

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

  unless record.project_name.present?
    record.errors.add(:project_name, :blank, '')

    return
  end

  validate_project_name record
end