Class: BanDisposableEmailValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/valid_email/ban_disposable_email_validator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.configObject

Required to use config outside



11
12
13
14
15
# File 'lib/valid_email/ban_disposable_email_validator.rb', line 11

def self.config
  @@config = [] unless defined? @@config

  @@config
end

.config=(options) ⇒ Object

A list of disposable email domains



6
7
8
# File 'lib/valid_email/ban_disposable_email_validator.rb', line 6

def self.config=(options)
  @@config = options
end

Instance Method Details

#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_email/ban_disposable_email_validator.rb', line 17

def validate_each(record, attribute, value)
  # Check if part of domain is in disposable_email_services yml list
  if options[:partial]
    r = ValidateEmail.ban_partial_disposable_email?(value)
    record.errors.add attribute, (options[:message] ||
      I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r

    r
  else
    r = ValidateEmail.ban_disposable_email?(value)
    record.errors.add attribute, (options[:message] ||
      I18n.t(:invalid, :scope => "valid_email.validations.email")) unless r

    r
  end
end