summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-01 19:30:01 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-07 16:57:26 -0500
commitad6a771dc680b52e4b46c73f20bc39340d08bf32 (patch)
treee0ad892d95a6251ede175a669ec682ec4dd771d5 /app/validators
parent96e51a0304022664c06a025f4a54c4a41c25edd2 (diff)
downloadgitlab-ce-ad6a771dc680b52e4b46c73f20bc39340d08bf32.tar.gz
Add custom LineCodeValidator
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/line_code_validator.rb12
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