Sha256: e95442d9932ee323da1c4f495763e526064ab83776e501ea8a6f5ff705e46ca8
Contents?: true
Size: 900 Bytes
Versions: 13
Compression:
Stored size: 900 Bytes
Contents
# frozen_string_literal: true 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
13 entries across 13 versions & 1 rubygems