Class: EmailValidator
- Inherits:
-
ActiveModel::EachValidator
- Object
- ActiveModel::EachValidator
- EmailValidator
- Defined in:
- lib/valid_email2.rb
Instance Method Summary collapse
- #default_options ⇒ Object
- #error(record, attribute) ⇒ Object
- #validate_each(record, attribute, value) ⇒ Object
Instance Method Details
#default_options ⇒ Object
13 14 15 |
# File 'lib/valid_email2.rb', line 13 def { regex: true, disposable: false, mx: false } end |
#error(record, attribute) ⇒ Object
34 35 36 |
# File 'lib/valid_email2.rb', line 34 def error(record, attribute) record.errors.add(attribute, [:message] || :invalid) end |
#validate_each(record, attribute, value) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/valid_email2.rb', line 17 def validate_each(record, attribute, value) return unless value.present? = .merge(self.) address = ValidEmail2::Address.new(value) error(record, attribute) && return unless address.valid? if [:disposable] error(record, attribute) && return if address.disposable? end if [:mx] error(record, attribute) && return unless address.valid_mx? end end |