Class: MemoryPersister

Inherits:
Object
  • Object
show all
Defined in:
lib/persisters/memory_persister.rb

Defined Under Namespace

Classes: Full, MemoryContainer

Instance Method Summary collapse

Constructor Details

#initialize(klass_list, options = {}) ⇒ MemoryPersister

Returns a new instance of MemoryPersister.



5
6
7
8
9
10
# File 'lib/persisters/memory_persister.rb', line 5

def initialize(klass_list, options = {})
  klass_list.each{ |klass| make_index_getters(klass) }
  sub_capacity = (options[:capacity] || 100000) / 2
  @new_container = MemoryContainer.new klass_list, capacity: sub_capacity
  @old_container = MemoryContainer.new klass_list, capacity: sub_capacity
end

Instance Method Details

#absorb(instance) ⇒ Object



12
13
14
15
16
17
# File 'lib/persisters/memory_persister.rb', line 12

def absorb(instance)
  @new_container.absorb instance
rescue MemoryPersister::Full
  rotate_containers
  absorb instance
end