Class: PEROBS::Array
- Inherits:
-
ObjectBase
- Object
- ObjectBase
- PEROBS::Array
- Defined in:
- lib/perobs/Array.rb
Overview
An Array that is transparently persisted onto the back-end storage. It is very similar to the Ruby built-in Array class but like other PEROBS object classes it converts direct references to other PEROBS objects into POXReference objects that only indirectly reference the other object. It also tracks all reads and write to any Array element and updates the cache accordingly.
We don’t support an Array.initialize_copy proxy as this would conflict with BasicObject.initialize_copy. You can use PEROBS::Array.replace() instead.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Attributes inherited from ObjectBase
Instance Method Summary collapse
-
#_delete_reference_to_id(id) ⇒ Object
This method should only be used during store repair operations.
-
#_deserialize(data) ⇒ Object
Restore the persistent data from a single data structure.
-
#_referenced_object_ids ⇒ Array of Fixnum or Bignum
Return a list of all object IDs of all persistend objects that this Array is referencing.
-
#initialize(store, size = 0, default = nil) ⇒ Array
constructor
New PEROBS objects must always be created by calling # Store.new().
Methods inherited from ObjectBase
#==, #_change_id, _finalize, #_restore, #_stash, #_sync, #post_restore, read
Constructor Details
#initialize(store, size = 0, default = nil) ⇒ Array
New PEROBS objects must always be created by calling # Store.new(). PEROBS users should never call this method or equivalents of derived methods directly.
86 87 88 89 |
# File 'lib/perobs/Array.rb', line 86 def initialize(store, size = 0, default = nil) super(store) @data = ::Array.new(size, default) end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
44 45 46 |
# File 'lib/perobs/Array.rb', line 44 def data @data end |
Instance Method Details
#_delete_reference_to_id(id) ⇒ Object
This method should only be used during store repair operations. It will delete all referenced to the given object ID.
103 104 105 106 107 |
# File 'lib/perobs/Array.rb', line 103 def _delete_reference_to_id(id) @data.delete_if do |v| v && v.respond_to?(:is_poxreference?) && v.id == id end end |
#_deserialize(data) ⇒ Object
Restore the persistent data from a single data structure. This is a library internal method. Do not use outside of this library.
113 114 115 116 |
# File 'lib/perobs/Array.rb', line 113 def _deserialize(data) @data = data.map { |v| v.is_a?(POReference) ? POXReference.new(@store, v.id) : v } end |
#_referenced_object_ids ⇒ Array of Fixnum or Bignum
Return a list of all object IDs of all persistend objects that this Array is referencing.
94 95 96 97 98 |
# File 'lib/perobs/Array.rb', line 94 def _referenced_object_ids @data.each.select do |v| v && v.respond_to?(:is_poxreference?) end.map { |o| o.id } end |