Class: Gitlab::Config::Entry::Validators::PortUniqueValidator

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

Direct Known Subclasses

JobPortUniqueValidator

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


323
324
325
326
327
328
329
330
331
332
333
# File 'lib/gitlab/config/entry/validators.rb', line 323

def validate_each(record, attribute, value)
  value = ports(value)
  return unless value.is_a?(Array)

  ports_size = value.count
  return if ports_size <= 1

  if transform_ports(value).size != ports_size
    record.errors.add(attribute, 'each port number can only be referenced once')
  end
end