Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project_path_validator.rb « validators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d41bdaeab8490204481b3d8bb4eb454ddd2afdb8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# ProjectPathValidator
#
# Custom validator for GitLab project path values.
#
# Values are checked for formatting and exclusion from a list of reserved path
# names.
#
# This is basically the same as the `NamespaceValidator` but it skips the validation
# of the format with `Gitlab::Regex.namespace_regex`. The format of projects
# is validated in the class itself.
class ProjectPathValidator < NamespaceValidator
  def self.valid?(value)
    !reserved?(value)
  end

  def self.reserved?(value, type: :wildcard)
    super(value, type: :wildcard)
  end

  delegate :reserved?, to: :class

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