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

line_code_validator.rb « validators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e1abccc1dffc7dedbe5f8fd1a3ec6825a97f776a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# frozen_string_literal: true

# LineCodeValidator
#
# Custom validator for GitLab line codes.
class LineCodeValidator < ActiveModel::EachValidator
  PATTERN = /\A[a-z0-9]+_\d+_\d+\z/.freeze

  def validate_each(record, attribute, value)
    unless PATTERN.match?(value)
      record.errors.add(attribute, "must be a valid line code")
    end
  end
end