Module: FIRM::Serializable::AliasManagement
- Included in:
- Aliasing
- Defined in:
- lib/firm/serializable.rb
Overview
This module provides alias (de-)serialization management functionality for output engines that do not provide this support out of the box.
Instance Method Summary collapse
-
#anchored?(object) ⇒ Boolean
Returns true if the object has an anchor registration, false otherwise.
- #clear_anchor_object_registry ⇒ Object
- #clear_anchor_references ⇒ Object
-
#get_anchor(object) ⇒ Integer?
Returns the anchor id if anchored, nil otherwise.
-
#get_anchor_data(object) ⇒ nil, Object
Retrieves the anchor serialization collection data for an anchored object.
-
#register_anchor_object(object, data) ⇒ Object
Registers a new anchor object.
-
#resolve_anchor(klass, id) ⇒ nil, Object
Resolves a referenced anchor instance.
-
#restore_anchor(id, object) ⇒ Object
Registers a restored anchor object and it’s ID.
-
#restored?(klass, id) ⇒ Boolean
Returns true if the anchor object for the given class and id has been restored, false otherwise.
- #start_anchor_object_registry ⇒ Object
- #start_anchor_references ⇒ Object
Instance Method Details
#anchored?(object) ⇒ Boolean
Returns true if the object has an anchor registration, false otherwise.
276 277 278 |
# File 'lib/firm/serializable.rb', line 276 def anchored?(object) class_anchor_objects(object.class).has_key?(object.object_id) end |
#clear_anchor_object_registry ⇒ Object
250 251 252 |
# File 'lib/firm/serializable.rb', line 250 def clear_anchor_object_registry anchor_object_registry_stack.pop end |
#clear_anchor_references ⇒ Object
304 305 306 |
# File 'lib/firm/serializable.rb', line 304 def clear_anchor_references anchor_references_stack.pop end |
#get_anchor(object) ⇒ Integer?
Returns the anchor id if anchored, nil otherwise.
283 284 285 |
# File 'lib/firm/serializable.rb', line 283 def get_anchor(object) anchored?(object) ? object.object_id : nil end |
#get_anchor_data(object) ⇒ nil, Object
Retrieves the anchor serialization collection data for an anchored object. Returns nil if the object is not anchored.
290 291 292 293 |
# File 'lib/firm/serializable.rb', line 290 def get_anchor_data(object) anchors = class_anchor_objects(object.class) anchors[object.object_id] end |
#register_anchor_object(object, data) ⇒ Object
Registers a new anchor object.
268 269 270 271 272 |
# File 'lib/firm/serializable.rb', line 268 def register_anchor_object(object, data) anchors = class_anchor_objects(object.class) raise Serializable::Exception, "Duplicate anchor creation for #{object}" if anchors.has_key?(object.object_id) anchors[object.object_id] = data end |
#resolve_anchor(klass, id) ⇒ nil, Object
Resolves a referenced anchor instance. Returns the instance if found, nil otherwise.
339 340 341 |
# File 'lib/firm/serializable.rb', line 339 def resolve_anchor(klass, id) class_anchor_references(klass)[id] end |
#restore_anchor(id, object) ⇒ Object
Registers a restored anchor object and it’s ID.
322 323 324 |
# File 'lib/firm/serializable.rb', line 322 def restore_anchor(id, object) class_anchor_references(object.class)[id] = object end |
#restored?(klass, id) ⇒ Boolean
Returns true if the anchor object for the given class and id has been restored, false otherwise.
330 331 332 |
# File 'lib/firm/serializable.rb', line 330 def restored?(klass, id) class_anchor_references(klass).has_key?(id) end |
#start_anchor_object_registry ⇒ Object
246 247 248 |
# File 'lib/firm/serializable.rb', line 246 def start_anchor_object_registry anchor_object_registry_stack.push({}) end |
#start_anchor_references ⇒ Object
300 301 302 |
# File 'lib/firm/serializable.rb', line 300 def start_anchor_references anchor_references_stack.push({}) end |