Class: LineCodeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/line_code_validator.rb

Overview

LineCodeValidator

Custom validator for GitLab line codes.

Constant Summary collapse

PATTERN =
/\A[a-z0-9]+_\d+_\d+\z/.freeze

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object


7
8
9
10
11
# File 'app/validators/line_code_validator.rb', line 7

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