diff options
| author | Douwe Maan <douwe@gitlab.com> | 2015-12-08 12:50:25 +0100 |
|---|---|---|
| committer | Douwe Maan <douwe@gitlab.com> | 2015-12-08 12:50:25 +0100 |
| commit | 3c80a543153f8f686ec99d2d04b181b2d2c8a665 (patch) | |
| tree | 679ca3921b00bd9e0904b4ad1be4e01d0a753ee9 /app/validators/line_code_validator.rb | |
| parent | 1a942111653e9376d6275c5bd31f23cb27f58ab5 (diff) | |
| parent | f5430e48b42227f1c1874ca27c6907f0f704be28 (diff) | |
| download | gitlab-ce-ui/misc.tar.gz | |
Merge branch 'master' into ui/miscui/misc
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 |
