Class: MiddleSquid::Indexer
- Inherits:
-
Object
- Object
- MiddleSquid::Indexer
- Includes:
- Database
- Defined in:
- lib/middle_squid/indexer.rb
Overview
Used internally to build the blacklist database.
Instance Attribute Summary collapse
Instance Method Summary collapse
- #blacklists=(list) ⇒ Object
- #index(directories) ⇒ Object
-
#initialize ⇒ Indexer
constructor
A new instance of Indexer.
Methods included from Database
Constructor Details
#initialize ⇒ Indexer
Returns a new instance of Indexer.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/middle_squid/indexer.rb', line 20 def initialize @append = false @entries = [:url, :domain] @full_index = true @quiet = false @aliases = {} @cats_in_use = [] @indexed_cats = [] @total = { :url => 0, :domain => 0, :ignored => 0, :duplicate => 0, } end |
Instance Attribute Details
#append ⇒ Boolean
9 10 11 |
# File 'lib/middle_squid/indexer.rb', line 9 def append @append end |
#entries ⇒ Array<Symbol>
12 13 14 |
# File 'lib/middle_squid/indexer.rb', line 12 def entries @entries end |
#full_index ⇒ Boolean
15 16 17 |
# File 'lib/middle_squid/indexer.rb', line 15 def full_index @full_index end |
#quiet ⇒ Boolean
18 19 20 |
# File 'lib/middle_squid/indexer.rb', line 18 def quiet @quiet end |
Instance Method Details
#blacklists=(list) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/middle_squid/indexer.rb', line 39 def blacklists=(list) @cats_in_use.clear @aliases.clear list.each {|bl| @cats_in_use << bl.category bl.aliases.each {|name| @aliases[name] = bl.category } } @cats_in_use.uniq! end |
#index(directories) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/middle_squid/indexer.rb', line 55 def index(directories) if !@full_index && @cats_in_use.empty? oops 'the loaded configuration does not use any blacklist' info 'nothing to do in minimal indexing mode' return end start_time = Time.now db.transaction truncate unless @append directories.each {|dir| walk_in dir } cats_summary stats commit_or_rollback end_time = Time.now info "finished after #{end_time - start_time} seconds" ensure db.rollback if db.transaction_active? end |