Class: Gitlab::Config::Entry::Validators::TypeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/gitlab/config/entry/validators.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



329
330
331
332
333
334
335
336
337
338
# File 'lib/gitlab/config/entry/validators.rb', line 329

def validate_each(record, attribute, value)
  type = options[:with]
  raise unless type.is_a?(Class)

  unless value.is_a?(type)
    article = type.name.match?(/\A[aeiou]/i) ? 'an' : 'a'
    message = options[:message] || "should be #{article} #{type.name.downcase}"
    record.errors.add(attribute, message)
  end
end