Module: Lutaml::Xml::PlanSerializer
- Defined in:
- lib/lutaml/xml/plan_serializer.rb
Overview
Serialize-side mirror of the plan fast path: builds the output tree directly through leptris's fused create_child chain — no XmlElement tree, no DeclarationPlanner pass, no builder context stack, no moxml wrapper minting. Serialized shapes must be the plain ones (attributes, scalars, collections, nested models, raw fragments, content runs); custom-method, polymorphic, union, and multi-spelling rows keep the interpretive serializer (their output flows through hash-shaped custom APIs).
Ordered/mixed models serialize from element_order when the instance carries one (parsed models): text runs, comments, and element entries in document order, mirroring the interpretive order applier — including its content-attr-first text reads (mutations to the model show up) and CDATA flattening. Models without element_order fall back interpretively (return nil).
Constant Summary collapse
- SERIALIZABLE_KINDS =
i[scalar collection_native collection_cb nested ordered_deferred raw content content_deferred].freeze
- CONTENT_KINDS =
i[content content_deferred].freeze
Class Method Summary collapse
-
.call(instance, plan) ⇒ Object
plan: the compiler's entry for instance's class.
-
.serializable?(plan) ⇒ Boolean
Whether the compiled plan is serialize-shaped.
Class Method Details
.call(instance, plan) ⇒ Object
plan: the compiler's entry for instance's class
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/lutaml/xml/plan_serializer.rb', line 28 def call(instance, plan) return nil if plan[:ordered] && instance.element_order.nil? doc = ::Leptris::XML::Document.create root = doc.create_element(plan[:tree][:name]) doc.root = root if plan[:ordered] build_ordered(root, instance, plan, doc) else build(root, instance, plan, doc) end doc.to_xml(indent: 2, no_decl: true) end |
.serializable?(plan) ⇒ Boolean
Whether the compiled plan is serialize-shaped. Ordered/mixed models serialize through build_ordered from element_order; plain models through plan rows.
45 46 47 48 49 |
# File 'lib/lutaml/xml/plan_serializer.rb', line 45 def serializable?(plan) plan[:rows].all? do |_rule, _attr, kind, _sp, _del| SERIALIZABLE_KINDS.include?(kind) end end |