Class: ActiveModel::Validations::EmailWhitelistValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/rails3/validates_email_whitelist_of.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/rails3/validates_email_whitelist_of.rb', line 4

def validate_each(record, attribute, value)
  if value.to_s !~ SimplesIdeias::ValidatesEmailWhitelistOf::EMAIL_FORMAT
    record.errors.add(attribute, :invalid_email, :default => options[:message], :value => value)
  else
    if options[:whitelist] && !options[:whitelist].include?($2)
      record.errors.add(attribute, :invalid_whitelist, :default => options[:message], :value => value)
    end

    if options[:blacklist] && options[:blacklist].include?($2)
      record.errors.add(attribute, :invalid_blacklist, :default => options[:message], :value => value)
    end
  end
end