Sha256: b67bffff948d249d8413d95b44bb394bda22cacd58e886580371d0564a470053

Contents?: true

Size: 1.1 KB

Versions: 16

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Truemail
  module Validate
    class ListMatch < Truemail::Validate::Base
      ERROR = 'blacklisted email'

      def run
        return success(true) if whitelisted? && !whitelist_validation?
        return unless whitelist_validation_case? || blacklisted?
        success(false)
        add_error(Truemail::Validate::ListMatch::ERROR)
      end

      private

      def email
        @email ||= result.email
      end

      def email_domain
        @email_domain ||=
          result.domain = email[Truemail::RegexConstant::REGEX_DOMAIN_FROM_EMAIL, 1]
      end

      def whitelisted?
        configuration.whitelisted_emails.include?(email) ||
          configuration.whitelisted_domains.include?(email_domain)
      end

      def whitelist_validation?
        configuration.whitelist_validation
      end

      def whitelist_validation_case?
        whitelist_validation? && !whitelisted?
      end

      def blacklisted?
        configuration.blacklisted_emails.include?(email) ||
          configuration.blacklisted_domains.include?(email_domain)
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
truemail-3.3.1 lib/truemail/validate/list_match.rb
truemail-3.3.0 lib/truemail/validate/list_match.rb
truemail-3.2.0 lib/truemail/validate/list_match.rb
truemail-3.1.2 lib/truemail/validate/list_match.rb
truemail-3.1.1 lib/truemail/validate/list_match.rb
truemail-3.1.0 lib/truemail/validate/list_match.rb
truemail-3.0.9 lib/truemail/validate/list_match.rb
truemail-3.0.8 lib/truemail/validate/list_match.rb
truemail-3.0.7 lib/truemail/validate/list_match.rb
truemail-3.0.6 lib/truemail/validate/list_match.rb
truemail-3.0.5 lib/truemail/validate/list_match.rb
truemail-3.0.4 lib/truemail/validate/list_match.rb
truemail-3.0.3 lib/truemail/validate/list_match.rb
truemail-3.0.2 lib/truemail/validate/list_match.rb
truemail-3.0.1 lib/truemail/validate/list_match.rb
truemail-3.0.0 lib/truemail/validate/list_match.rb