Module: Lutaml::Xml::TransformationSupport::OrderReconciler
- Included in:
- Lutaml::Xml::Transformation
- Defined in:
- lib/lutaml/xml/transformation/order_reconciler.rb
Overview
Aligns a model's element_order with the values it currently holds.
element_order describes the source document, not the model. Anything assigned after parsing has no entry in it, so OrderedApplier would never emit that value. Reconciliation inserts the missing entries before serialization starts.
Only insertion is needed. A collection that shrank already emits the right count, because process_collection_item stops yielding once the index passes the value length.
The model's own element_order is never modified: the reconciled array is a local view, so repeated to_xml calls stay idempotent.
Instance Method Summary collapse
-
#reconciled_element_order(model_instance, compiled_rules, options) ⇒ Array(Array, Array<CompiledRule>)
The element order with any missing entries inserted, and the rules it could not reconcile that still hold an unemitted value.
Instance Method Details
#reconciled_element_order(model_instance, compiled_rules, options) ⇒ Array(Array, Array<CompiledRule>)
Returns the element order with any missing entries inserted, and the rules it could not reconcile that still hold an unemitted value. The caller must emit those the ordinary way or their value is lost. When nothing is missing the model's own order comes back untouched.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/lutaml/xml/transformation/order_reconciler.rb', line 28 def reconciled_element_order(model_instance, compiled_rules, ) order = model_instance.element_order element_rules = element_typed_rules(compiled_rules) # Resolve every entry to its rule once. Coverage, insertion # anchors and the final array all read from this, so no later # step rescans the order or re-matches a rule. resolved = order.map { |object| find_rule_for_element(object, compiled_rules) } coverage = ::Hash.new(0) resolved.each { |rule| coverage[rule] += 1 if rule } deficits, fallback = classify_rules(element_rules, coverage, model_instance, ) return [order, fallback] if deficits.empty? [insert_deficits(order, deficits, element_rules, resolved), fallback] end |