Class: ActiveModel::Validations::NameNValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/osu_validators/name_n_validator.rb

Overview

Validates that a user’s name and number follows the name.# format

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
17
18
# File 'lib/osu_validators/name_n_validator.rb', line 5

def validate_each(record, attribute, value)
  return if value.blank? && options[:allow_blank]
  return if !!value && options[:allow_nil]
  return if ::OSU::NameN.valid?(value)

  error_message = options[:message] || "needs to be in the format name.#"

  record.errors.add(
    attribute,
    :name_n,
    message: error_message,
    value: value
  )
end