require "email_assessor/email_validator"

module EmailAssessor
  DISPOSABLE_DOMAINS_FILE = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
  BLACKLISTED_DOMAINS_FILE = File.expand_path("vendor/blacklisted_domains.txt")

  def self.domain_is_disposable?(domain)
    domain_in_file?(domain, DISPOSABLE_DOMAINS_FILE)
  end

  def self.domain_is_blacklisted?(domain)
    domain_in_file?(domain, BLACKLISTED_DOMAINS_FILE)
  end

  protected

  def self.domain_in_file?(domain, filename)
    return false unless File.exists?(filename)

    domain = domain.downcase
    domain_matched = false

    File.open(filename).each do |line|
      if domain.end_with?(line.chomp)
        domain_matched = true
        break
      end
    end

    domain_matched
  end
end

require "email_assessor/email_validator"

module EmailAssessor
  DISPOSABLE_DOMAINS_FILE = File.expand_path("../../vendor/disposable_domains.txt", __FILE__)
  BLACKLISTED_DOMAINS_FILE = File.expand_path("vendor/blacklisted_domains.txt")

  def self.domain_is_disposable?(domain)
    domain_in_file?(domain, DISPOSABLE_DOMAINS_FILE)
  end

  def self.domain_is_blacklisted?(domain)
    domain_in_file?(domain, BLACKLISTED_DOMAINS_FILE)
  end

  protected

  def self.domain_in_file?(domain, filename)
    return false unless filename.present? && File.exists?(filename)

    domain = domain.downcase
    domain_matched = false

    File.open(filename).each do |line|
      if domain.end_with?(line.chomp)
        domain_matched = true
        break
      end
    end

    domain_matched
  end
end

Check that a file name was provided before checking if the file exists
Check that a file name was provided before checking if the file exists
