lib/validators/tld.rb in validators-3.3.0 vs lib/validators/tld.rb in validators-3.4.0

- old
+ new

@@ -1,23 +1,27 @@ # frozen_string_literal: true module Validators class TLD - FILE_PATH = File.expand_path("../../data/tld.txt", __dir__) - def self.all - @all ||= File.read(FILE_PATH).lines.map(&:chomp) + @all ||= + begin + require "email_data" + EmailData.tlds + rescue LoadError + raise "email_data is not part of the bundle. Add it to Gemfile." + end end def self.host_with_valid_tld?(host) host = host.to_s return false if host.split(".").size == 1 - valid?(host[/\.([^.]+)$/, 1].to_s.downcase) + include?(host[/\.([^.]+)$/, 1].to_s.downcase) end - def self.valid?(tld) + def self.include?(tld) all.include?(tld) end end end