Module: ValidatesHostname::Tld

Defined in:
lib/validates_hostname.rb

Overview

Handles TLD list loading and management.

Constant Summary collapse

ALLOWED_TLDS =
load_tlds

Class Method Summary collapse

Class Method Details

.load_tldsObject

List from IANA: www.iana.org/domains/root/db/

http://data.iana.org/TLD/tlds-alpha-by-domain.txt


12
13
14
15
16
17
18
19
20
# File 'lib/validates_hostname.rb', line 12

def self.load_tlds
  tlds_file_path = File.expand_path('../data/tlds.txt', __dir__)
  Set.new(File.readlines(tlds_file_path)
          .map(&:strip)
          .map(&:downcase)
          .reject { |line| line.start_with?('#') || line.empty? })
     .add('.')
     .freeze
end