Class: ActiveModel::Validations::EmailValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::EmailValidator
- Defined in:
- lib/validators/validates_email_format_of.rb
Constant Summary collapse
- AT_SIGN =
"@"
Instance Method Summary collapse
- #validate_disposable_domain(record, attribute, value, _options) ⇒ Object
- #validate_disposable_email(record, attribute, value, _options) ⇒ Object
- #validate_each(record, attribute, value) ⇒ Object
- #validate_email_format(record, attribute, value, options) ⇒ Object
- #validate_tld(record, attribute, value, options) ⇒ Object
Instance Method Details
#validate_disposable_domain(record, attribute, value, _options) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/validators/validates_email_format_of.rb', line 45 def validate_disposable_domain(record, attribute, value, ) return unless value hostname = value.to_s.split(AT_SIGN).last.to_s.downcase root_domain = RootDomain.call(hostname) return unless Validators::DisposableDomains.include?(root_domain) record.errors.add( attribute, :disposable_domain, value: value ) end |
#validate_disposable_email(record, attribute, value, _options) ⇒ Object
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/validators/validates_email_format_of.rb', line 60 def validate_disposable_email(record, attribute, value, ) return unless value return unless Validators::DisposableEmails.include?(value) record.errors.add( attribute, :disposable_email, value: value ) end |
#validate_each(record, attribute, value) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/validators/validates_email_format_of.rb', line 8 def validate_each(record, attribute, value) allow_disposable = .fetch(:disposable, false) check_tld = .fetch(:tld, false) return if value.blank? && [:allow_blank] return if value.nil? && [:allow_nil] validate_tld(record, attribute, value, ) if check_tld validate_email_format(record, attribute, value, ) validate_disposable_domain(record, attribute, value, ) unless allow_disposable validate_disposable_email(record, attribute, value, ) unless allow_disposable end |
#validate_email_format(record, attribute, value, options) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/validators/validates_email_format_of.rb', line 21 def validate_email_format(record, attribute, value, ) return if value.to_s =~ Validators::EMAIL_FORMAT return if value.to_s =~ Validators::MICROSOFT_EMAIL_FORMAT record.errors.add( attribute, :invalid_email, message: [:message], value: value ) end |
#validate_tld(record, attribute, value, options) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/validators/validates_email_format_of.rb', line 33 def validate_tld(record, attribute, value, ) host = value.to_s.split(AT_SIGN).last return if Validators::TLD.host_with_valid_tld?(host) record.errors.add( attribute, :invalid_hostname, message: [:message], value: value ) end |