Class: ActiveModel::Validations::EmailValidator
- Inherits:
-
EachValidator
- Object
- EachValidator
- ActiveModel::Validations::EmailValidator
- Defined in:
- lib/validators/validates_email_format_of.rb
Instance Method Summary collapse
- #validate_disposable_email(record, attribute, value, options) ⇒ Object
- #validate_each(record, attribute, value) ⇒ Object
- #validate_email_format(record, attribute, value, options) ⇒ Object
Instance Method Details
#validate_disposable_email(record, attribute, value, options) ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/validators/validates_email_format_of.rb', line 23 def validate_disposable_email(record, attribute, value, ) hostname = value.to_s.split("@").last.to_s.downcase record.errors.add( attribute, :disposable_email, :value => value ) if Validators::DisposableHostnames.all.include?(hostname) end |
#validate_each(record, attribute, value) ⇒ Object
4 5 6 7 8 9 10 11 12 |
# File 'lib/validators/validates_email_format_of.rb', line 4 def validate_each(record, attribute, value) allow_disposable = .fetch(:disposable, false) return if value.blank? && [:allow_blank] return if value.nil? && [:allow_nil] validate_email_format(record, attribute, value, ) validate_disposable_email(record, attribute, value, ) unless allow_disposable end |
#validate_email_format(record, attribute, value, options) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/validators/validates_email_format_of.rb', line 14 def validate_email_format(record, attribute, value, ) if value.to_s !~ Validators::EMAIL_FORMAT record.errors.add( attribute, :invalid_email, :message => [:message], :value => value ) end end |