blob: a351180790ed5fce10d4df955409537873761476 (
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 value =~ PATTERN
record.errors.add(attribute, "must be a valid line code")
end
end
end
|