2018-11-08 19:23:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
# 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
|