Module: FIRM::Serializable::XML::SerializeInstanceMethods

Included in:
ID, SerializeInstanceMethods
Defined in:
lib/firm/serializer/xml.rb

Overview

extend instance serialization methods

Instance Method Summary collapse

Instance Method Details

#to_xml(xml) ⇒ Object



541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
# File 'lib/firm/serializer/xml.rb', line 541

def to_xml(xml)
  node = xml.add_child(Nokogiri::XML::Node.new('Object', xml.document))
  node['class'] = self.class.name
  if (anchor = Serializable::Aliasing.get_anchor(self))
    anchor_data = Serializable::Aliasing.get_anchor_data(self)
    # retroactively insert the anchor in the anchored instance's serialization data
    anchor_data['anchor'] = anchor unless anchor_data.has_attribute?('anchor')
    node['alias'] = "#{anchor}"
  else
    # register anchor object **before** serializing properties to properly handle cycling (bidirectional
    # references)
    Serializable::Aliasing.register_anchor_object(self, node)
    for_serialize(XML::HashAdapter.new(node))
  end
  xml
end