summaryrefslogtreecommitdiff
path: root/app/validators/line_code_validator.rb
blob: ed29e5aeb67f08f3e401db4c0f5f815ecf4766b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
# 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 value =~ PATTERN
      record.errors.add(attribute, "must be a valid line code")
    end
  end
end