class Validators::ReservedSubdomains

Constants

FILE_PATH

Public Class Methods

all() click to toggle source
# File lib/validators/reserved_subdomains.rb, line 13
def self.all
  @all ||= File.read(FILE_PATH).lines.map {|matcher| parse(matcher.chomp) }
end
match?(matcher, hostname) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 36
def self.match?(matcher, hostname)
  case matcher
  when String
    matcher == hostname
  when Regexp
    hostname =~ matcher
  else
    raise "Unknown matcher type: #{matcher.class}"
  end
end
match_any?(matchers, hostname) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 27
def self.match_any?(matchers, hostname)
  hostname = normalize(hostname)
  matchers.any? {|matcher| match?(matcher, hostname) }
end
normalize(hostname) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 32
def self.normalize(hostname)
  hostname.downcase.gsub(/[_-]/, "")
end
parse(matcher) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 17
def self.parse(matcher)
  return matcher unless matcher.start_with?("/")

  Regexp.compile(matcher[%r{/(.*?)/}, 1])
end
parse_list(matchers) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 23
def self.parse_list(matchers)
  matchers.map {|matcher| parse(matcher) }
end
reserved?(hostname, matchers = nil) click to toggle source
# File lib/validators/reserved_subdomains.rb, line 7
def self.reserved?(hostname, matchers = nil)
  matchers = parse_list(matchers) if matchers
  matchers ||= all
  match_any?(matchers, hostname)
end