Class: Picky::Indexers::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/picky/indexers/base.rb

Direct Known Subclasses

Parallel, Serial

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(index_or_category) ⇒ Base

Returns a new instance of Base.



16
17
18
# File 'lib/picky/indexers/base.rb', line 16

def initialize index_or_category
  @index_or_category = index_or_category
end

Instance Attribute Details

#index_or_categoryObject (readonly)

Returns the value of attribute index_or_category.



11
12
13
# File 'lib/picky/indexers/base.rb', line 11

def index_or_category
  @index_or_category
end

Instance Method Details

#check(source) ⇒ Object



38
39
40
# File 'lib/picky/indexers/base.rb', line 38

def check source
  raise "Trying to index without a source for #{@index_or_category.name}." unless source
end

#notify_finished(prepared_file) ⇒ Object



42
43
44
# File 'lib/picky/indexers/base.rb', line 42

def notify_finished prepared_file
  Picky.logger.tokenize @index_or_category, prepared_file
end

#prepare(categories, scheduler = Scheduler.new) ⇒ Object

Starts the indexing process.



22
23
24
25
26
27
28
29
# File 'lib/picky/indexers/base.rb', line 22

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

#reset(source) ⇒ Object

Explicitly reset the source to avoid caching trouble.



33
34
35
36
# File 'lib/picky/indexers/base.rb', line 33

def reset source
  source.reset      if source.respond_to?(:reset)
  source.reconnect! if source.respond_to?(:reconnect!)
end