Class: MiddleSquid::BlackList
- Inherits:
-
Object
- Object
- MiddleSquid::BlackList
- Includes:
- Database
- Defined in:
- lib/middle_squid/blacklist.rb
Overview
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 (otherwise they would not be seen by the “middle_squid index
” command unless the “--full
” flag is enabled).
Instance Attribute Summary collapse
-
#aliases ⇒ Array<String>
readonly
The aliases passed to #initialize.
-
#category ⇒ String
readonly
The category passed to #initialize.
Instance Method Summary collapse
-
#include?(uri) ⇒ Boolean
Whether this blacklists contains the uri.
-
#include_domain?(uri) ⇒ Boolean
Whether the blacklist category contains the URI’s hostname or an upper-level domain.
-
#include_url?(uri) ⇒ Boolean
Whether the blacklist category contains the URI.
-
#initialize(category, aliases: []) ⇒ BlackList
constructor
Returns a new instance of BlackList.
Methods included from Database
Constructor Details
#initialize(category, aliases: []) ⇒ BlackList
Returns a new instance of BlackList. Use Builder#blacklist instead.
19 20 21 22 |
# File 'lib/middle_squid/blacklist.rb', line 19 def initialize(category, aliases: []) @category = category @aliases = aliases end |
Instance Attribute Details
#aliases ⇒ Array<String> (readonly)
Returns the aliases passed to #initialize.
14 15 16 |
# File 'lib/middle_squid/blacklist.rb', line 14 def aliases @aliases end |
#category ⇒ String (readonly)
Returns the category passed to #initialize.
11 12 13 |
# File 'lib/middle_squid/blacklist.rb', line 11 def category @category end |
Instance Method Details
#include?(uri) ⇒ Boolean
Whether this blacklists contains the uri. Matches by domain and/or path.
63 64 65 |
# File 'lib/middle_squid/blacklist.rb', line 63 def include?(uri) include_domain?(uri) || include_url?(uri) end |
#include_domain?(uri) ⇒ Boolean
Whether the blacklist category contains the URI’s hostname or an upper-level domain.
Rules to the www
subdomain match any subdomains.
34 35 36 37 38 39 |
# 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) ⇒ Boolean
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.
52 53 54 55 56 57 |
# 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 |