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)


241
242
243
# File 'lib/firm/serializable.rb', line 241

def anchored?(object)
  class_anchor_objects(object.class).has_key?(object.object_id)
end

#clear_anchor_object_registryObject



215
216
217
# File 'lib/firm/serializable.rb', line 215

def clear_anchor_object_registry
  anchor_object_registry_stack.pop
end

#clear_anchor_referencesObject



269
270
271
# File 'lib/firm/serializable.rb', line 269

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)


248
249
250
# File 'lib/firm/serializable.rb', line 248

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)


255
256
257
258
# File 'lib/firm/serializable.rb', line 255

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:



233
234
235
236
237
# File 'lib/firm/serializable.rb', line 233

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)


304
305
306
# File 'lib/firm/serializable.rb', line 304

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



287
288
289
# File 'lib/firm/serializable.rb', line 287

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)


295
296
297
# File 'lib/firm/serializable.rb', line 295

def restored?(klass, id)
  class_anchor_references(klass).has_key?(id)
end

#start_anchor_object_registryObject



211
212
213
# File 'lib/firm/serializable.rb', line 211

def start_anchor_object_registry
  anchor_object_registry_stack.push({})
end

#start_anchor_referencesObject



265
266
267
# File 'lib/firm/serializable.rb', line 265

def start_anchor_references
  anchor_references_stack.push({})
end