/
base.rb
50 lines (38 loc) · 1.07 KB
/
base.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# encoding: utf-8
#
module Picky
module Indexers
#
#
class Base
attr_reader :index_or_category
forward :source,
:to => :index_or_category
def initialize index_or_category
@index_or_category = index_or_category
end
# Starts the indexing process.
#
def prepare categories, scheduler = Scheduler.new
source_for_prepare = source
check source_for_prepare
categories.empty
process source_for_prepare, categories, scheduler do |prepared_file|
notify_finished prepared_file
end
end
# Explicitly reset the source to avoid caching trouble.
#
def reset source
source.reset if source.respond_to?(:reset)
source.reconnect! if source.respond_to?(:reconnect!)
end
def check source
raise "Trying to index without a source for #{@index_or_category.name}." unless source
end
def notify_finished prepared_file
Picky.logger.tokenize @index_or_category, prepared_file
end
end
end
end