Class: ActiveRecord::Bulkoperation::Util::SequenceCache

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord_bulkoperation/util/sequence_cache.rb

Instance Method Summary collapse

Constructor Details

#initialize(seq, prefetch = 10) ⇒ SequenceCache

seq - the sequence name to use with the SequenceCache object refetch - how many values should be fetch from the database with each roundtrip



17
18
19
20
# File 'lib/activerecord_bulkoperation/util/sequence_cache.rb', line 17

def initialize(seq, prefetch = 10)          
  @seq, @prefetch = seq, prefetch
  @queue = Queue.new
end

Instance Method Details

#next_valueObject

return - the next value from the sequence



24
25
26
27
28
29
# File 'lib/activerecord_bulkoperation/util/sequence_cache.rb', line 24

def next_value          
  while ( value = next_value_from_queue ).nil?
    fill_queue
  end
  value 
end