Sha256: 0c651161f9820ea891a5ca1cd5a1338d2d61e0a771cccf0ab0af214ab250efbb

Contents?: true

Size: 899 Bytes

Versions: 2

Compression:

Stored size: 899 Bytes

Contents

require 'naughty_or_nice'

class PeerReview < NaughtyOrNice
  class << self
    # returns an instance of our custom public suffix list
    # list behaves like PublicSuffix::List but is limited to our whitelisted domains
    def list
      @list ||= PublicSuffix::List::parse(File.new(list_path, "r:utf-8"))
    end

    # Returns the absolute path to the domain list
    def list_path
      File.expand_path("../config/domains.txt", File.dirname(__FILE__))
    end
  end

  # Checks if the input string represents a research domain
  def valid?
    # Ensure it's a valid domain
    return false unless PublicSuffix.valid?(domain)

    # check using public suffix's standard logic
    rule = PeerReview.list.find domain
    return true if !rule.nil? && rule.allow?(domain)

    # also allow for explicit matches to domain list
    PeerReview.list.rules.any? { |rule| rule.value == domain }
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
peer_review-0.0.3 lib/peer_review.rb
peer_review-0.0.2 lib/peer_review.rb