Class: MemoryPersister::MemoryContainer
- Inherits:
-
Object
- Object
- MemoryPersister::MemoryContainer
- Defined in:
- lib/persisters/memory_persister.rb
Instance Method Summary collapse
- #absorb(instance) ⇒ Object
- #capacity_left ⇒ Object
- #clear ⇒ Object
-
#initialize(klass_list, options = {}) ⇒ MemoryContainer
constructor
A new instance of MemoryContainer.
Constructor Details
#initialize(klass_list, options = {}) ⇒ MemoryContainer
Returns a new instance of MemoryContainer.
45 46 47 48 49 |
# File 'lib/persisters/memory_persister.rb', line 45 def initialize(klass_list, = {}) klass_list.each {|klass| make_index_getters klass } @capacity = [:capacity] || 65535 clear end |
Instance Method Details
#absorb(instance) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/persisters/memory_persister.rb', line 51 def absorb(instance) raise MemoryPersister::Full if self.capacity_left <= 0 klass = instance.class klass.get_instance_indices.each do |index| instances[klass.to_s]["__#{index}"][instance.send(index)] = instance end @capacity_used += 1 end |
#capacity_left ⇒ Object
60 61 62 |
# File 'lib/persisters/memory_persister.rb', line 60 def capacity_left @capacity - @capacity_used end |
#clear ⇒ Object
64 65 66 67 |
# File 'lib/persisters/memory_persister.rb', line 64 def clear @instances = new_instances_hash @capacity_used = 0 end |