class Sunspot::Batcher

Keeps a stack of batches and helps out when Indexer is asked to batch documents.

If the client does something like

Sunspot.batch do
  some_code_here
  which_triggers_some_other_code
  which_again_calls
  Sunspot.batch { ... }
end

it is the Batcher’s job to keep track of these nestings. The inner will be sent off to be indexed first.

Public Instance Methods

<<(value) click to toggle source
Alias for: push
batching?() click to toggle source
# File lib/sunspot/batcher.rb, line 45
def batching?
  depth > 0
end
concat(values) click to toggle source
# File lib/sunspot/batcher.rb, line 58
def concat(values)
  current.concat values
end
current() click to toggle source
# File lib/sunspot/batcher.rb, line 27
def current
  @stack.last or start_new
end
depth() click to toggle source
# File lib/sunspot/batcher.rb, line 41
def depth
  @stack.length
end
each(&block) click to toggle source
# File lib/sunspot/batcher.rb, line 49
def each(&block)
  current.each(&block)
end
end_current() click to toggle source
# File lib/sunspot/batcher.rb, line 35
def end_current
  fail NoCurrentBatchError if @stack.empty?

  @stack.pop
end
push(value) click to toggle source
# File lib/sunspot/batcher.rb, line 53
def push(value)
  current << value
end
Also aliased as: <<
start_new() click to toggle source
# File lib/sunspot/batcher.rb, line 31
def start_new
  (@stack << []).last
end

Public Class Methods

new() click to toggle source
# File lib/sunspot/batcher.rb, line 23
def initialize
  @stack = []
end