Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-02 03:30:01 +0300
committerRobert Speicher <rspeicher@gmail.com>2015-12-08 00:57:26 +0300
commitad6a771dc680b52e4b46c73f20bc39340d08bf32 (patch)
treee0ad892d95a6251ede175a669ec682ec4dd771d5 /app/validators
parent96e51a0304022664c06a025f4a54c4a41c25edd2 (diff)
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