Class: NamespaceValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/namespace_validator.rb

Overview

NamespaceValidator

Custom validator for GitLab namespace values.

Values are checked for formatting and exclusion from a list of reserved path names.

Constant Summary collapse

RESERVED =
%w(
  admin
  all
  assets
  ci
  dashboard
  files
  groups
  help
  hooks
  issues
  merge_requests
  new
  notes
  profile
  projects
  public
  repository
  s
  search
  services
  snippets
  teams
  u
  unsubscribes
  users
).freeze

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


36
37
38
39
40
41
42
43
44
# File 'app/validators/namespace_validator.rb', line 36

def validate_each(record, attribute, value)
  unless value =~ Gitlab::Regex.namespace_regex
    record.errors.add(attribute, Gitlab::Regex.namespace_regex_message)
  end

  if reserved?(value)
    record.errors.add(attribute, "#{value} is a reserved name")
  end
end