Sha256: 8897170cfebcf9d392b2af7c9ff0b35b8fbe5a0fe27ce5d7b25f4ddbc5079c73

Contents?: true

Size: 1016 Bytes

Versions: 27

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

require "valid_email2/email_validator"

module ValidEmail2
  BLACKLIST_FILE  = "config/blacklisted_email_domains.yml"
  WHITELIST_FILE  = "config/whitelisted_email_domains.yml"
  DISPOSABLE_FILE = File.expand_path('../config/disposable_email_domains.txt', __dir__)

  class << self
    def disposable_emails
      @disposable_emails ||= load_file(DISPOSABLE_FILE)
    end

    def blacklist
      @blacklist ||= load_if_exists(BLACKLIST_FILE)
    end

    def whitelist
      @whitelist ||= load_if_exists(WHITELIST_FILE)
    end

    private

    def load_if_exists(path)
      File.exist?(path) ? load_file(path) : Set.new
    end

    def load_file(path)
      # This method MUST return a Set, otherwise the
      # performance will suffer!
      if path.end_with?(".yml")
        Set.new(YAML.load_file(path))
      else
        File.open(path, "r").each_line.each_with_object(Set.new) do |domain, set|
          set << domain.tap(&:chomp!)
        end
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
valid_email2-5.2.6 lib/valid_email2.rb
valid_email2-5.2.5 lib/valid_email2.rb
valid_email2-5.2.4 lib/valid_email2.rb
valid_email2-5.2.3 lib/valid_email2.rb
valid_email2-5.2.1 lib/valid_email2.rb
valid_email2-5.2.0 lib/valid_email2.rb
valid_email2-5.1.1 lib/valid_email2.rb
valid_email2-5.1.0 lib/valid_email2.rb
valid_email2-5.0.5 lib/valid_email2.rb
valid_email2-5.0.4 lib/valid_email2.rb
valid_email2-5.0.3 lib/valid_email2.rb
valid_email2-5.0.2 lib/valid_email2.rb
valid_email2-5.0.1 lib/valid_email2.rb
valid_email2-5.0.0 lib/valid_email2.rb
valid_email2-4.0.6 lib/valid_email2.rb
valid_email2-4.0.5 lib/valid_email2.rb
valid_email2-4.0.4 lib/valid_email2.rb
valid_email2-4.0.3 lib/valid_email2.rb
valid_email2-4.0.2 lib/valid_email2.rb
valid_email2-4.0.1 lib/valid_email2.rb