Sha256: aa81a760b4cda73716a7fa3193fff41bcc7209cd3fe4a2d64b7d0ca0345d1b56
Contents?: true
Size: 870 Bytes
Versions: 18
Compression:
Stored size: 870 Bytes
Contents
require "email_assessor/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 = EmailAssessor::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
18 entries across 18 versions & 1 rubygems