Sha256: 2d58894bfb51e4fb0a48cf619b7423508809edd297f114d883a2d2090878f402

Contents?: true

Size: 665 Bytes

Versions: 24

Compression:

Stored size: 665 Bytes

Contents

module Riveter
  class EmailValidator < ActiveModel::EachValidator
    def initialize(options)
      @allow_nil, @allow_blank = options.delete(:allow_nil), options.delete(:allow_blank)
      super
    end

    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
  end
end

# add compatibility with ActiveModel validates method which
# matches option keys to their validator class
ActiveModel::Validations::EmailValidator = Riveter::EmailValidator

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
riveter-0.8.3 lib/riveter/email_validator.rb
riveter-0.8.2 lib/riveter/email_validator.rb
riveter-0.8.1 lib/riveter/email_validator.rb
riveter-0.8.0 lib/riveter/email_validator.rb
riveter-0.7.0 lib/riveter/email_validator.rb
riveter-0.6.0 lib/riveter/email_validator.rb
riveter-0.3.0 lib/riveter/email_validator.rb
riveter-0.2.1 lib/riveter/email_validator.rb
riveter-0.2.0 lib/riveter/email_validator.rb
riveter-0.1.1 lib/riveter/email_validator.rb
riveter-0.0.15 lib/riveter/email_validator.rb
riveter-0.0.14 lib/riveter/email_validator.rb
riveter-0.0.13 lib/riveter/email_validator.rb
riveter-0.0.12 lib/riveter/email_validator.rb
riveter-0.0.11 lib/riveter/email_validator.rb
riveter-0.0.10 lib/riveter/email_validator.rb
riveter-0.0.9 lib/riveter/email_validator.rb
riveter-0.0.8 lib/riveter/email_validator.rb
riveter-0.0.7 lib/riveter/email_validator.rb
riveter-0.0.6 lib/riveter/email_validator.rb