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

Instance Method Details

#anchored?(object) ⇒ Boolean

Returns true if the object has an anchor registration, false otherwise.

Returns:

  • (Boolean)


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_registryObject



250
251
252
# File 'lib/firm/serializable.rb', line 250

def clear_anchor_object_registry
  anchor_object_registry_stack.pop
end

#clear_anchor_referencesObject



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.

Parameters:

  • object (Object)

    anchor instance

Returns:

  • (Integer, nil)


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.

Returns:

  • (nil, Object)


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.

Parameters:

  • object (Object)

    anchor instance

  • data (Object)

    serialized property collection object

Returns:

  • (Object)

    serialized property collection object

Raises:



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.

Parameters:

  • klass (Class)

    aliasable class of the anchor instance

  • id (Integer)

    anchor id

Returns:

  • (nil, Object)


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.

Parameters:

  • id (Integer)

    anchor ID

  • object (Object)

    anchor instance

Returns:

  • (Object)

    anchor instance



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.

Parameters:

  • klass (Class)

    aliasable class of the anchor instance

  • id (Integer)

    anchor id

Returns:

  • (Boolean)


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_registryObject



246
247
248
# File 'lib/firm/serializable.rb', line 246

def start_anchor_object_registry
  anchor_object_registry_stack.push({})
end

#start_anchor_referencesObject



300
301
302
# File 'lib/firm/serializable.rb', line 300

def start_anchor_references
  anchor_references_stack.push({})
end