class MiddleSquid::BlackList

Use to query the blacklist database. URIs can be matched by hostname (see {#include_domain?}), path (see {#include_url?}) or both (see {#include?}).

Instances of this class should be created using {Builder#blacklist Builder#blacklist} (otherwise they would not be seen by the “middle_squid index” command unless the “--full” flag is enabled).

Attributes

aliases[R]

@return [Array<String>] the aliases passed to {#initialize}

category[R]

@return [String] the category passed to {#initialize}

Public Class Methods

new(category, aliases: []) click to toggle source

Returns a new instance of BlackList. Use {Builder#blacklist Builder#blacklist} instead. @param category [String] @param aliases [Array<String>]

# File lib/middle_squid/blacklist.rb, line 19
def initialize(category, aliases: [])
  @category = category
  @aliases = aliases
end

Public Instance Methods

include?(uri) click to toggle source

Whether this blacklists contains the uri. Matches by domain and/or path.

@param uri [URI] the uri to search

# File lib/middle_squid/blacklist.rb, line 63
def include?(uri)
  include_domain?(uri) || include_url?(uri)
end
include_domain?(uri) click to toggle source

Whether the blacklist category contains the URI's hostname or an upper-level domain.

Rules to the www subdomain match any subdomains.

@example Rule: sub.domain.com

Matches:
- http://sub.domain.com/...
- http://second.sub.domain.com/...
- http://infinite.level.of.sub.domain.com/...

@param uri [URI] the URI to search

# File lib/middle_squid/blacklist.rb, line 34
def include_domain?(uri)
  !!db.get_first_value(
    "SELECT 1 FROM domains WHERE category = ? AND ? LIKE '%' || host LIMIT 1",
    [@category, uri.cleanhost]
  )
end
include_url?(uri) click to toggle source

Whether the blacklist category contains the URI. Matches by partial domain (like {#include_domain?}) and path. The query string is ignored.

Rules to index files (index.html, Default.aspx and friends) match the whole directory.

@example Rule: domain.com/path

Matches:
- http://domain.com/path
- http://domain.com/dummy/../path
- http://domain.com/path/extra_path
- http://domain.com/path?query=string

@param uri [URI] the URI to search

# File lib/middle_squid/blacklist.rb, line 52
def include_url?(uri)
  !!db.get_first_value(
    "SELECT 1 FROM urls WHERE category = ? AND ? LIKE '%' || host AND ? LIKE path || '%' LIMIT 1",
    [@category, uri.cleanhost, uri.cleanpath]
  )
end