summaryrefslogtreecommitdiff
path: root/app/validators
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-12-01 19:21:45 -0500
committerRobert Speicher <rspeicher@gmail.com>2015-12-07 16:57:26 -0500
commit96e51a0304022664c06a025f4a54c4a41c25edd2 (patch)
tree483d7997946db4bc6f8ed51187ca1d6538dca016 /app/validators
parente48391b813d3e5079238aa3f0662e7a46e1b4a54 (diff)
downloadgitlab-ce-96e51a0304022664c06a025f4a54c4a41c25edd2.tar.gz
Minor EmailValidator refactor
Diffstat (limited to 'app/validators')
-rw-r--r--app/validators/email_validator.rb11
1 files changed, 4 insertions, 7 deletions
diff --git a/app/validators/email_validator.rb b/app/validators/email_validator.rb
index f509f0a5843..b35af100803 100644
--- a/app/validators/email_validator.rb
+++ b/app/validators/email_validator.rb
@@ -1,3 +1,5 @@
+# EmailValidator
+#
# Based on https://github.com/balexand/email_validator
#
# Extended to use only strict mode with following allowed characters:
@@ -6,15 +8,10 @@
# See http://www.remote.org/jochen/mail/info/chars.html
#
class EmailValidator < ActiveModel::EachValidator
- @@default_options = {}
-
- def self.default_options
- @@default_options
- end
+ PATTERN = /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i.freeze
def validate_each(record, attribute, value)
- options = @@default_options.merge(self.options)
- unless value =~ /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i
+ unless value =~ PATTERN
record.errors.add(attribute, options[:message] || :invalid)
end
end