class Riveter::EmailValidator

Private Class Methods

new(options) click to toggle source
Calls superclass method
# File lib/riveter/email_validator.rb, line 3
def initialize(options)
  @allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
  super
end

Private Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/riveter/email_validator.rb, line 8
def validate_each(record, attribute, value)
  return if (@allow_nil && value.nil?) || (@allow_blank && value.blank?)

  unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
    record.errors.add(attribute, :email, :value => value)
  end
end