lutaml-model 0.8.205 → 0.8.207
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/_guides/native-engines.adoc +25 -3
- data/docs/cli_compare.adoc +4 -0
- data/lib/lutaml/model/cli.rb +7 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/plan_based_builder.rb +16 -0
- data/lib/lutaml/xml/adapter/xml_parser.rb +10 -5
- data/lib/lutaml/xml/adapter/xml_serializer.rb +1 -0
- data/lib/lutaml/xml/leptris/native_emission.rb +30 -7
- data/lib/lutaml/xml/leptris/plan_compiler.rb +59 -15
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +55 -17
- data/lib/lutaml/xml/leptris/plan_serializer.rb +167 -29
- data/lib/lutaml/xml/model_transform.rb +9 -2
- data/lutaml-model.gemspec +1 -1
- data/spec/fixtures/lml_conformance/core/manifest.json +1 -1
- data/spec/fixtures/lml_conformance/preservation/manifest.json +1 -1
- data/spec/lutaml/model/cli_spec.rb +4 -5
- data/spec/lutaml/model/group_spec.rb +7 -2
- data/spec/lutaml/model/lml_review_round5_spec.rb +7 -3
- data/spec/lutaml/model/render_nil_spec.rb +2 -1
- data/spec/lutaml/model/value_map_spec.rb +18 -16
- data/spec/lutaml/xml/production_lane_parity_spec.rb +416 -0
- data/spec/spec_helper.rb +18 -1
- metadata +6 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d100be5e75a2c176f69d9367bc66bf67ea65655ca6c181047b9aa97b1b985ac2
|
|
4
|
+
data.tar.gz: '09942944fdc1ef7e16a229e56d88e07c4304307748dd6fe0cafc846f688299e2'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8474edf89b9345787bc78e804d8b1495cdb144a3d0e8c4821a11e1943634dc8b7d2c32ba5dc1d17e25d40290a2ed83691a668f472c34d537195ba9367ddc4b72
|
|
7
|
+
data.tar.gz: fbedc7fb3cee383cd5351cbd35f4205af91f052331be46eceba41839bc1dd14451176a73ba30b20c583592f5e4b039fa40f7da802f9856b3d279243a930b99a3
|
|
@@ -82,9 +82,31 @@ whose `elementFormDefault` is not set are in no namespace: under a
|
|
|
82
82
|
default-namespace root they opt out with `xmlns=""`; an explicitly
|
|
83
83
|
`unqualified` form keeps the default-namespace root and bare locals;
|
|
84
84
|
`render_nil` / `render_empty` policies render their `xsi:nil` or blank
|
|
85
|
-
element exactly as the standard pipeline does.
|
|
86
|
-
|
|
87
|
-
|
|
85
|
+
element exactly as the standard pipeline does. A model declaring a
|
|
86
|
+
`sequence` records its parse-built element order on the fast path too,
|
|
87
|
+
so `validate` reports an out-of-order member there as it does on the
|
|
88
|
+
standard pipeline. Two shapes ride the standard pipeline by design —
|
|
89
|
+
`raw: :content` captures (an element's inner XML) and a singular
|
|
90
|
+
attribute typed as a `Collection`, whose own root element rides under
|
|
91
|
+
the mapped one — and one stays interpretive for an engine reason: an
|
|
92
|
+
`xsi:nil` mark on a nested element (below the root's own children),
|
|
93
|
+
which the engine walk does not surface.
|
|
94
|
+
|
|
95
|
+
Round trips keep what the parsed root declared. Every namespace the
|
|
96
|
+
source declared on the root is declared again — an extra vocabulary the
|
|
97
|
+
document carried, the prefix a captured raw fragment spells, or a
|
|
98
|
+
second prefix a default-namespace root bound its own namespace to —
|
|
99
|
+
exactly as the standard pipeline keeps them. A `render_nil` element
|
|
100
|
+
spells `xsi:nil`, and a constructed document declares the `xsi` prefix
|
|
101
|
+
for it on the root (a parsed one already carries the declaration).
|
|
102
|
+
|
|
103
|
+
Parsing strictness is a property of the lane unless you ask for
|
|
104
|
+
otherwise: the leptris plan lane parses strictly (malformed input
|
|
105
|
+
raises `InvalidFormatError`), while the standard pipeline recovers
|
|
106
|
+
whatever its engine recovers — Nokogiri recovers most malformed input
|
|
107
|
+
into a best-effort tree. `from_xml(xml, strict: true)` asks for the
|
|
108
|
+
raising contract on every lane; the `lutaml-model compare` command
|
|
109
|
+
always parses strictly.
|
|
88
110
|
|
|
89
111
|
Version floor note: leptris 1.9.320+ retains child-row namespace
|
|
90
112
|
URIs engine-side and matches plain attribute rows against
|
data/docs/cli_compare.adoc
CHANGED
|
@@ -233,6 +233,10 @@ Error parsing file data.xml: Invalid XML syntax
|
|
|
233
233
|
----
|
|
234
234
|
*Solution:* Verify file format and syntax. The CLI will attempt to parse files according to their extension.
|
|
235
235
|
|
|
236
|
+
XML files are parsed strictly: a malformed document is reported as above
|
|
237
|
+
rather than compared as a recovered tree, whatever the engine would have
|
|
238
|
+
recovered from it.
|
|
239
|
+
|
|
236
240
|
== Supported File Formats
|
|
237
241
|
|
|
238
242
|
The compare command automatically detects file format based on extension:
|
data/lib/lutaml/model/cli.rb
CHANGED
|
@@ -70,7 +70,13 @@ module Lutaml
|
|
|
70
70
|
format = path.split(".").last.downcase
|
|
71
71
|
format = "yaml" if format == "yml"
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
if format == "xml"
|
|
74
|
+
# A malformed document is reported, never compared as a
|
|
75
|
+
# recovered tree — whatever the engine would recover.
|
|
76
|
+
model.from_xml(content, strict: true)
|
|
77
|
+
else
|
|
78
|
+
model.public_send("from_#{format}", content)
|
|
79
|
+
end
|
|
74
80
|
rescue StandardError => e
|
|
75
81
|
raise StandardError, "Error parsing file #{path}: #{e.message}"
|
|
76
82
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -294,6 +294,7 @@ module Lutaml
|
|
|
294
294
|
# Check if element was created from nil value with render_nil option
|
|
295
295
|
if element.is_a?(Lutaml::Xml::DataModel::XmlElement) && element.xsi_nil
|
|
296
296
|
attributes["xsi:nil"] = true
|
|
297
|
+
declare_xsi_prefix(xml)
|
|
297
298
|
end
|
|
298
299
|
|
|
299
300
|
# Create element
|
|
@@ -472,6 +473,21 @@ module Lutaml
|
|
|
472
473
|
|
|
473
474
|
private
|
|
474
475
|
|
|
476
|
+
# xsi:nil spells the xsi prefix: the document root declares it,
|
|
477
|
+
# as it does for xsi:schemaLocation (a parsed source's own
|
|
478
|
+
# declaration is kept by the stored plan, so this adds nothing
|
|
479
|
+
# on a round trip).
|
|
480
|
+
def declare_xsi_prefix(xml)
|
|
481
|
+
root = xml.doc.root
|
|
482
|
+
return unless root
|
|
483
|
+
return if root.in_scope_namespaces.any? do |ns|
|
|
484
|
+
ns.prefix == W3c::XsiNamespace.prefix_default
|
|
485
|
+
end
|
|
486
|
+
|
|
487
|
+
root.add_namespace(W3c::XsiNamespace.prefix_default,
|
|
488
|
+
W3c::XsiNamespace.uri)
|
|
489
|
+
end
|
|
490
|
+
|
|
475
491
|
def build_type_only_element(xml, element, xml_mapping, plan, options,
|
|
476
492
|
mapper_class)
|
|
477
493
|
if options[:tag_name]
|
|
@@ -17,7 +17,8 @@ module Lutaml
|
|
|
17
17
|
parse_encoding = encoding(xml, options)
|
|
18
18
|
raw_xml = xml
|
|
19
19
|
xml = normalize_xml_for_parse(xml)
|
|
20
|
-
parsed = parse_with_moxml(xml, parse_encoding
|
|
20
|
+
parsed = parse_with_moxml(xml, parse_encoding,
|
|
21
|
+
strict: options[:strict])
|
|
21
22
|
root_element = parsed.root
|
|
22
23
|
|
|
23
24
|
raise_empty_document_error(parsed.parse_errors) if root_element.nil?
|
|
@@ -46,15 +47,19 @@ module Lutaml
|
|
|
46
47
|
replace: "?")
|
|
47
48
|
end
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
# strict: the engine raises on malformed input instead of
|
|
51
|
+
# recovering a best-effort tree (what a `from_xml(strict: true)`
|
|
52
|
+
# caller asks for; the leptris plan lane parses strictly anyway).
|
|
53
|
+
def parse_with_moxml(xml, parse_encoding, strict: nil)
|
|
50
54
|
parse_error_class = parse_error_class_or_nil
|
|
55
|
+
moxml_options = { encoding: parse_encoding }
|
|
56
|
+
moxml_options[:strict] = true if strict
|
|
51
57
|
unless parse_error_class
|
|
52
|
-
return moxml_adapter_class.parse(xml,
|
|
53
|
-
encoding: parse_encoding)
|
|
58
|
+
return moxml_adapter_class.parse(xml, **moxml_options)
|
|
54
59
|
end
|
|
55
60
|
|
|
56
61
|
begin
|
|
57
|
-
moxml_adapter_class.parse(xml,
|
|
62
|
+
moxml_adapter_class.parse(xml, **moxml_options)
|
|
58
63
|
rescue parse_error_class => e
|
|
59
64
|
raise Lutaml::Model::InvalidFormatError.new(:xml, e.message)
|
|
60
65
|
end
|
|
@@ -264,6 +264,7 @@ module Lutaml
|
|
|
264
264
|
|
|
265
265
|
if xml_element.is_a?(Lutaml::Xml::DataModel::XmlElement) && xml_element.xsi_nil
|
|
266
266
|
attributes["xsi:nil"] = "true"
|
|
267
|
+
declare_xsi_prefix(xml)
|
|
267
268
|
end
|
|
268
269
|
|
|
269
270
|
attributes.merge!(element_node.schema_location_attr) if element_node.schema_location_attr
|
|
@@ -60,6 +60,16 @@ module Lutaml
|
|
|
60
60
|
# A nil instance runs the static checks only.
|
|
61
61
|
def compatible?(plan, instance = nil, register = nil)
|
|
62
62
|
return false if plan.nil?
|
|
63
|
+
# Source declarations the ops layout cannot spell (an extra
|
|
64
|
+
# vocabulary the parsed root declared, a second prefix for a
|
|
65
|
+
# declared namespace): the DOM lane re-declares them.
|
|
66
|
+
return false if instance &&
|
|
67
|
+
PlanSerializer.stored_declarations_uncovered?(plan, instance)
|
|
68
|
+
# A tracked element_order on an unordered plan (#977) is the
|
|
69
|
+
# DOM lane's ordered walk; the flat ops layout emits mapping
|
|
70
|
+
# order.
|
|
71
|
+
return false if instance && !plan[:ordered] &&
|
|
72
|
+
PlanSerializer.ordered_walk?(plan, instance)
|
|
63
73
|
return false if namespaced_tree?(plan[:tree]) &&
|
|
64
74
|
!engine_ns_prefix_safe?
|
|
65
75
|
return false unless ordered_ns_emittable?(plan, instance)
|
|
@@ -283,6 +293,14 @@ module Lutaml
|
|
|
283
293
|
return true unless instance.is_a?(::Lutaml::Model::Serialize)
|
|
284
294
|
|
|
285
295
|
plan[:rows].each do |(rule, attr, kind, _sp, delegate, _type)|
|
|
296
|
+
# Content runs of an unordered plan interleave with the
|
|
297
|
+
# element children (the interpretive apply_mixed_content);
|
|
298
|
+
# the flat ops layout emits mapping order.
|
|
299
|
+
if !plan[:ordered] && attr &&
|
|
300
|
+
PlanSerializer::CONTENT_KINDS.include?(kind) &&
|
|
301
|
+
value_of(instance, attr, delegate).is_a?(::Array)
|
|
302
|
+
return false
|
|
303
|
+
end
|
|
286
304
|
next unless rule.name
|
|
287
305
|
|
|
288
306
|
# A type hooking the XML format through its own to_xml is
|
|
@@ -638,6 +656,10 @@ module Lutaml
|
|
|
638
656
|
text_node_index += 1
|
|
639
657
|
next if text.nil?
|
|
640
658
|
next if content_attr.nil? && text.strip.empty?
|
|
659
|
+
# Text with no content row to ride (mixed content whose
|
|
660
|
+
# text is unmapped) has no ops spelling: the DOM lane
|
|
661
|
+
# emits it as a bare text node.
|
|
662
|
+
return nil unless content_entry
|
|
641
663
|
|
|
642
664
|
op_slot(buf, len)
|
|
643
665
|
buf[len][:kind] = :scalar
|
|
@@ -701,7 +723,7 @@ module Lutaml
|
|
|
701
723
|
buf[len][:plan_index] = my_index
|
|
702
724
|
buf[len][:row_index] = row_index
|
|
703
725
|
len += 1
|
|
704
|
-
len = if child_plan
|
|
726
|
+
len = if PlanSerializer.ordered_walk?(child_plan, item)
|
|
705
727
|
emit_ordered(buf, len, item, child_plan, register,
|
|
706
728
|
child_index, graph)
|
|
707
729
|
else
|
|
@@ -843,11 +865,12 @@ module Lutaml
|
|
|
843
865
|
len += 1
|
|
844
866
|
end
|
|
845
867
|
when :content, :content_deferred
|
|
846
|
-
#
|
|
847
|
-
#
|
|
848
|
-
#
|
|
849
|
-
#
|
|
850
|
-
# ordered lane's
|
|
868
|
+
# Content text rides SCALAR ops on the content row
|
|
869
|
+
# itself — the engine renders CONTENT-kind rows as bare
|
|
870
|
+
# escaped text. A run array on an unordered plan never
|
|
871
|
+
# lands here (the gate refuses it: the runs interleave
|
|
872
|
+
# with the element children); the ordered lane's
|
|
873
|
+
# unordered leaves do.
|
|
851
874
|
Array(value).each do |run|
|
|
852
875
|
op_slot(buf, len)
|
|
853
876
|
buf[len][:kind] = :scalar
|
|
@@ -876,7 +899,7 @@ module Lutaml
|
|
|
876
899
|
buf[len][:plan_index] = my_index
|
|
877
900
|
buf[len][:row_index] = row_index
|
|
878
901
|
len += 1
|
|
879
|
-
len = if child_plan
|
|
902
|
+
len = if PlanSerializer.ordered_walk?(child_plan, item)
|
|
880
903
|
emit_ordered(buf, len, item, child_plan, register,
|
|
881
904
|
child_index, graph)
|
|
882
905
|
else
|
|
@@ -50,13 +50,20 @@ module Lutaml
|
|
|
50
50
|
|
|
51
51
|
# Name-matched element row kinds eligible for the :unqualified
|
|
52
52
|
# ns form (leptris#1560). Text rows (content) match no element
|
|
53
|
-
# name and wildcard rows carry their own :any.
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
# name and wildcard rows carry their own :any. Raw captures are
|
|
54
|
+
# absent on purpose: the interpretive matcher binds a raw rule
|
|
55
|
+
# by local name whatever the prefix ("capture any element with
|
|
56
|
+
# that name"), so a raw row keeps the any-qualification form.
|
|
57
|
+
ROW_KINDS_NS_UNQUALIFIED = %i[scalar collection nested callback].freeze
|
|
56
58
|
# Row kinds whose hydration can dispatch per source node —
|
|
57
59
|
# the only safe claimants of a contested (multi-row) name.
|
|
58
60
|
PER_NODE_ROW_KINDS = %i[nested ordered_deferred
|
|
59
61
|
child_deferred].freeze
|
|
62
|
+
# Row kinds that read the per-name source-node buckets; a plan
|
|
63
|
+
# keeping its node for another reason (a sequence's element_order
|
|
64
|
+
# record) builds no buckets without one of these.
|
|
65
|
+
BUCKET_ROW_KINDS = %i[nested ordered_deferred child_deferred
|
|
66
|
+
custom_method polymorphic].freeze
|
|
60
67
|
|
|
61
68
|
# Signature holder: the (attribute count, rule count) a plan was
|
|
62
69
|
# compiled against, keyed like PLAN_CACHE.
|
|
@@ -282,6 +289,12 @@ module Lutaml
|
|
|
282
289
|
attr.collection? ? :content : :content_deferred,
|
|
283
290
|
nil, delegate_ref]
|
|
284
291
|
rows << { name: "__content__#{compiled.size}", kind: :content }
|
|
292
|
+
elsif raw_content_rule?(rule, attr)
|
|
293
|
+
# raw: :content captures the element's INNER XML: no row
|
|
294
|
+
# kind spells it (a scalar row captures the text only,
|
|
295
|
+
# an :element row the whole fragment). The interpretive
|
|
296
|
+
# reader owns the shape.
|
|
297
|
+
return opt_out!(:content_raw)
|
|
285
298
|
elsif rule.raw_mapping? || rule.raw == :element
|
|
286
299
|
compiled << [rule, attr, :raw, nil, delegate_ref]
|
|
287
300
|
rows << { name: rule.name.to_s, kind: :raw }
|
|
@@ -298,21 +311,14 @@ module Lutaml
|
|
|
298
311
|
rows << { name: rule.name.to_s, kind: :raw }
|
|
299
312
|
else
|
|
300
313
|
type = attr.type(register)
|
|
314
|
+
return opt_out!(:nested_collection) if nested_collection_attribute?(attr, type)
|
|
315
|
+
|
|
301
316
|
if serializable_type?(type)
|
|
302
317
|
child = compile(type, register)
|
|
303
|
-
if
|
|
304
|
-
|
|
305
|
-
child_mapping = type.mappings_for(:xml, register)
|
|
306
|
-
if child_mapping&.ordered? ||
|
|
307
|
-
child_mapping&.mixed_content?
|
|
308
|
-
# A child refused ONLY by the ordered opt-in gate
|
|
309
|
-
# cascades: the bridged-island deferral drops its
|
|
310
|
-
# mixed children (customxml schemaRefs), so the
|
|
311
|
-
# parent compiles to nil — main's whole-model
|
|
312
|
-
# interpretive shape.
|
|
313
|
-
return opt_out!(:ordered_opt_in_cascade)
|
|
314
|
-
end
|
|
318
|
+
if ordered_cascade_refusal?(type, register, child)
|
|
319
|
+
return opt_out!(:ordered_opt_in_cascade)
|
|
315
320
|
end
|
|
321
|
+
|
|
316
322
|
needs_nodes = true if child.nil? || child[:ordered]
|
|
317
323
|
compiled_entry, row = child_row_for(rule, attr, type, child,
|
|
318
324
|
delegate_ref,
|
|
@@ -470,11 +476,20 @@ module Lutaml
|
|
|
470
476
|
return nil
|
|
471
477
|
end
|
|
472
478
|
|
|
479
|
+
# Sequence validation reads the parse-built element_order
|
|
480
|
+
# (validate → order_names): a model declaring a sequence
|
|
481
|
+
# records it from its source node, nested instances
|
|
482
|
+
# included, like the ordered shapes.
|
|
483
|
+
sequence = !mapping.element_sequence.empty?
|
|
484
|
+
needs_nodes = true if sequence
|
|
485
|
+
|
|
473
486
|
{ descriptor: descriptor, tree: tree, rows: compiled,
|
|
474
487
|
attr_rows: attr_rows, mapping: mapping,
|
|
475
488
|
row_tags: row_tags, namespaced: namespaced,
|
|
476
489
|
ordered: mapping.ordered? || mapping.mixed_content?,
|
|
490
|
+
sequence: sequence,
|
|
477
491
|
needs_nodes: needs_nodes,
|
|
492
|
+
needs_buckets: compiled.any? { |row| BUCKET_ROW_KINDS.include?(row[2]) },
|
|
478
493
|
contested_names: contested.empty? ? nil : contested,
|
|
479
494
|
ns_attr_names: ns_attr_names.empty? ? nil : ns_attr_names,
|
|
480
495
|
wildcard_tag: (wildcard_tag if defined?(wildcard_tag)) }
|
|
@@ -798,6 +813,35 @@ module Lutaml
|
|
|
798
813
|
attr.polymorphic? || attr.union?
|
|
799
814
|
end
|
|
800
815
|
|
|
816
|
+
# The unified raw mode (the interpretive rule compiler's
|
|
817
|
+
# resolve_raw_mode): the rule's own, else the attribute's
|
|
818
|
+
# raw flag. :content captures the inner XML.
|
|
819
|
+
def raw_content_rule?(rule, attr)
|
|
820
|
+
mode = rule.raw || (attr.raw? ? :content : nil)
|
|
821
|
+
mode == :content
|
|
822
|
+
end
|
|
823
|
+
|
|
824
|
+
# A singular attribute typed as a Collection carries the
|
|
825
|
+
# collection's own root under the mapped element (the
|
|
826
|
+
# interpretive nested_collection_attribute unwrap) — a
|
|
827
|
+
# wrapper-plus-root shape no row spells.
|
|
828
|
+
def nested_collection_attribute?(attr, type)
|
|
829
|
+
attr.singular? && type.is_a?(Class) &&
|
|
830
|
+
type <= ::Lutaml::Model::Collection
|
|
831
|
+
end
|
|
832
|
+
|
|
833
|
+
# A child refused ONLY by the ordered opt-in gate cascades: the
|
|
834
|
+
# bridged-island deferral drops its mixed children (customxml
|
|
835
|
+
# schemaRefs), so the parent compiles to nil — main's
|
|
836
|
+
# whole-model interpretive shape.
|
|
837
|
+
def ordered_cascade_refusal?(type, register, child)
|
|
838
|
+
return false unless child.nil?
|
|
839
|
+
return false if Lutaml::Model::Config.instance.xml_plan_ordered_path
|
|
840
|
+
|
|
841
|
+
child_mapping = type.mappings_for(:xml, register)
|
|
842
|
+
child_mapping&.ordered? || child_mapping&.mixed_content?
|
|
843
|
+
end
|
|
844
|
+
|
|
801
845
|
def scalar_type?(attr, register)
|
|
802
846
|
type = attr.type(register)
|
|
803
847
|
type.is_a?(Class) && type < ::Lutaml::Model::Type::Value &&
|
|
@@ -48,11 +48,12 @@ module Lutaml
|
|
|
48
48
|
# duplicate name/URI strings inside the summaries. One
|
|
49
49
|
# shared table per parse collapses them to distinct strings.
|
|
50
50
|
intern ||= {}
|
|
51
|
-
buckets = if node && plan[:needs_nodes]
|
|
51
|
+
buckets = if node && plan[:needs_nodes] && plan[:needs_buckets]
|
|
52
52
|
element_buckets(node, plan[:contested_names])
|
|
53
53
|
end
|
|
54
54
|
attr_kwargs = attributes_kwargs(plan, value, node, register)
|
|
55
|
-
child_kwargs, children, delegates, run_children
|
|
55
|
+
child_kwargs, children, delegates, run_children,
|
|
56
|
+
element_children =
|
|
56
57
|
children_kwargs(model_class, plan, value, buckets, register,
|
|
57
58
|
intern, node: node)
|
|
58
59
|
# A collection absent from the document keeps the
|
|
@@ -76,8 +77,11 @@ module Lutaml
|
|
|
76
77
|
instance.xml_namespace_prefix = node.prefix
|
|
77
78
|
end
|
|
78
79
|
# #909: order summaries are per-instance pinned records —
|
|
79
|
-
# read-only consumers skip them via the config.
|
|
80
|
-
|
|
80
|
+
# read-only consumers skip them via the config. Ordered and
|
|
81
|
+
# sequence models record them: the ordered walk replays
|
|
82
|
+
# them, and sequence validation reads the element names in
|
|
83
|
+
# document order (without the record it silently passes).
|
|
84
|
+
if node && (plan[:ordered] || plan[:sequence]) &&
|
|
81
85
|
Lutaml::Model::Config.instance.element_order_tracking
|
|
82
86
|
instance.element_order = PlanOrder.build(node, intern)
|
|
83
87
|
end
|
|
@@ -97,7 +101,8 @@ module Lutaml
|
|
|
97
101
|
child.lutaml_root ||= instance.lutaml_root || instance
|
|
98
102
|
end
|
|
99
103
|
interpret_deferred(model_class, plan, value, instance, node,
|
|
100
|
-
buckets, run_children
|
|
104
|
+
buckets, run_children,
|
|
105
|
+
element_children: element_children)
|
|
101
106
|
route_delegates(delegates, instance, register)
|
|
102
107
|
CollectionConsolidation.call(instance, register)
|
|
103
108
|
instance
|
|
@@ -330,11 +335,10 @@ module Lutaml
|
|
|
330
335
|
context: nil)
|
|
331
336
|
end
|
|
332
337
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
end
|
|
338
|
+
# The interpretive transform_value: class transformers on
|
|
339
|
+
# the rule or the attribute, in order (its own fast path
|
|
340
|
+
# returns the value when there are none).
|
|
341
|
+
rule.transform_value(attr, value, :from, :xml)
|
|
338
342
|
end
|
|
339
343
|
|
|
340
344
|
# The interpretive reader casts a Value type that hooks the XML
|
|
@@ -612,7 +616,10 @@ module Lutaml
|
|
|
612
616
|
attr.collection? ? values : values.first)
|
|
613
617
|
end
|
|
614
618
|
end
|
|
615
|
-
|
|
619
|
+
# grouped holds the captured element rows: non-empty means
|
|
620
|
+
# the source element has element children (the content
|
|
621
|
+
# shape below reads it).
|
|
622
|
+
[kwargs, children, delegates, run_children, !grouped.empty?]
|
|
616
623
|
end
|
|
617
624
|
|
|
618
625
|
# Deferred islands: raw subtrees become wrapper elements via a
|
|
@@ -623,7 +630,8 @@ module Lutaml
|
|
|
623
630
|
# node (no fragment parse — the reparse dominated deferred
|
|
624
631
|
# hydration). Ordered children only land here without a node.
|
|
625
632
|
def interpret_deferred(model_class, plan, value, instance, node = nil,
|
|
626
|
-
buckets = nil, run_children = nil
|
|
633
|
+
buckets = nil, run_children = nil,
|
|
634
|
+
element_children: false)
|
|
627
635
|
# Array#each + top counter: no per-node enumerator (see
|
|
628
636
|
# children_kwargs).
|
|
629
637
|
rows = plan[:rows]
|
|
@@ -654,10 +662,16 @@ module Lutaml
|
|
|
654
662
|
next
|
|
655
663
|
end
|
|
656
664
|
|
|
657
|
-
#
|
|
658
|
-
#
|
|
659
|
-
#
|
|
660
|
-
|
|
665
|
+
# A singular content attribute takes the interpretive
|
|
666
|
+
# reader's shape: the text runs when the element has
|
|
667
|
+
# non-text children (validate flags a singular target
|
|
668
|
+
# holding them), the joined text otherwise.
|
|
669
|
+
# Several runs mean non-text nodes between them (text
|
|
670
|
+
# nodes only split at a child boundary).
|
|
671
|
+
instance.public_send(:"#{attr.name}=",
|
|
672
|
+
content_text(node, runs,
|
|
673
|
+
element_children ||
|
|
674
|
+
runs.size > 1))
|
|
661
675
|
when :raw
|
|
662
676
|
raws = raw_strings(value, wire_name)
|
|
663
677
|
next if raws.empty?
|
|
@@ -668,7 +682,16 @@ module Lutaml
|
|
|
668
682
|
elements = deferred_elements(value, wire_name, buckets)
|
|
669
683
|
next if elements.empty?
|
|
670
684
|
|
|
671
|
-
|
|
685
|
+
# The interpretive reader's custom-method contract: a
|
|
686
|
+
# singular attribute receives its one element, or the
|
|
687
|
+
# whole array on an over-count (#185); the rule's
|
|
688
|
+
# transform runs first, on that same value.
|
|
689
|
+
args = if attr.collection? || elements.size > 1
|
|
690
|
+
elements
|
|
691
|
+
else
|
|
692
|
+
elements.first
|
|
693
|
+
end
|
|
694
|
+
args = import_transformed(rule, attr, args)
|
|
672
695
|
rule.deserialize(instance, args,
|
|
673
696
|
model_class.attributes(register),
|
|
674
697
|
model_class)
|
|
@@ -825,6 +848,21 @@ module Lutaml
|
|
|
825
848
|
end
|
|
826
849
|
end
|
|
827
850
|
|
|
851
|
+
# The interpretive XmlElement#text shape for a singular
|
|
852
|
+
# content attribute: the text runs when the source element has
|
|
853
|
+
# non-text children (mixed content), the joined text otherwise.
|
|
854
|
+
# Mapped element children and child-split runs show in the
|
|
855
|
+
# walk's own capture; a single run beside an unmapped element
|
|
856
|
+
# only on the source node, consulted when the hydration already
|
|
857
|
+
# holds it (the buckets chain is not kept for this — 85
|
|
858
|
+
# singular content attributes ride every NISO JATS paragraph).
|
|
859
|
+
def content_text(node, runs, element_children)
|
|
860
|
+
return runs if element_children
|
|
861
|
+
return runs.join unless node
|
|
862
|
+
|
|
863
|
+
node.first_element_child.nil? ? runs.join : runs
|
|
864
|
+
end
|
|
865
|
+
|
|
828
866
|
# Native collection rows echo their producing row's name
|
|
829
867
|
# (leptris 1.9.178).
|
|
830
868
|
def native_collection(value, name)
|