diff options
author | Robert Speicher <rspeicher@gmail.com> | 2015-12-02 03:30:01 +0300 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2015-12-08 00:57:26 +0300 |
commit | ad6a771dc680b52e4b46c73f20bc39340d08bf32 (patch) | |
tree | e0ad892d95a6251ede175a669ec682ec4dd771d5 /app/validators/line_code_validator.rb | |
parent | 96e51a0304022664c06a025f4a54c4a41c25edd2 (diff) |
Add custom LineCodeValidator
Diffstat (limited to 'app/validators/line_code_validator.rb')
-rw-r--r-- | app/validators/line_code_validator.rb | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/app/validators/line_code_validator.rb b/app/validators/line_code_validator.rb new file mode 100644 index 00000000000..ed29e5aeb67 --- /dev/null +++ b/app/validators/line_code_validator.rb @@ -0,0 +1,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 |