Module: Lutaml::Xml::Serialization::CollectionExt

Defined in:
lib/lutaml/xml/serialization/collection_ext.rb

Overview

XML-specific overrides for Collection class methods.

Prepended into Collection’s singleton class when XML is loaded. Provides XML-specific no_root handling for collections.

Instance Method Summary collapse

Instance Method Details

#collection_no_root_to(format, mappings, instance, options) ⇒ Object

XML no_root serialization: serialize each mapping separately



26
27
28
29
30
31
32
# File 'lib/lutaml/xml/serialization/collection_ext.rb', line 26

def collection_no_root_to(format, mappings, instance, options)
  return super unless format == :xml

  mappings.mappings.map do |mapping|
    serialize_for_mapping(mapping, instance, format, options)
  end.join("\n")
end

#collection_no_root_to?(format) ⇒ Boolean

XML handles no_root serialization specially

Returns:

  • (Boolean)


19
20
21
22
23
# File 'lib/lutaml/xml/serialization/collection_ext.rb', line 19

def collection_no_root_to?(format)
  return super unless format == :xml

  true
end

#collection_structured_format?(format) ⇒ Boolean

XML is a structured (tree-based) format

Returns:

  • (Boolean)


12
13
14
15
16
# File 'lib/lutaml/xml/serialization/collection_ext.rb', line 12

def collection_structured_format?(format)
  return super unless format == :xml

  true
end

#wrap_no_root_input(format, mappings, data) ⇒ Object

XML no_root: wrap raw XML in a fake root tag before parsing



35
36
37
38
39
40
# File 'lib/lutaml/xml/serialization/collection_ext.rb', line 35

def wrap_no_root_input(format, mappings, data)
  return super unless format == :xml

  tag_name = mappings.find_by_to!(instance_name).name
  "<#{tag_name}>#{data}</#{tag_name}>"
end