Sha256: 8e1d16b5a1c6b8bb534848855463ad09cc48a3d8a01262d5a8f1a9e919255e89
Contents?: true
Size: 866 Bytes
Versions: 37
Compression:
Stored size: 866 Bytes
Contents
require "valid_email2/address" require "active_model" require "active_model/validations" class EmailValidator < ActiveModel::EachValidator def default_options { regex: true, disposable: false, mx: false } end def validate_each(record, attribute, value) return unless value.present? options = default_options.merge(self.options) address = ValidEmail2::Address.new(value) error(record, attribute) && return unless address.valid? if options[:disposable] error(record, attribute) && return if address.disposable? end if options[:blacklist] error(record, attribute) && return if address.blacklisted? end if options[:mx] error(record, attribute) && return unless address.valid_mx? end end def error(record, attribute) record.errors.add(attribute, options[:message] || :invalid) end end
Version data entries
37 entries across 37 versions & 1 rubygems