lutaml-model 0.8.95 → 0.8.97
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/grammar-backed-formats.adoc +69 -0
- data/docs/_guides/index.adoc +2 -0
- data/lib/lutaml/model/serialize/attribute_definition.rb +133 -7
- data/lib/lutaml/model/serialize/format_conversion.rb +13 -2
- data/lib/lutaml/model/serialize/initialization.rb +25 -7
- data/lib/lutaml/model/serialize/model_import.rb +39 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model.rb +7 -0
- data/lib/lutaml/xml/format.rb +8 -10
- data/lib/lutaml/xml/leptris/plan_compiler.rb +137 -22
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +34 -1
- data/lib/lutaml/xml/leptris/plan_serializer.rb +174 -18
- data/lib/lutaml/xml/leptris/plan_walk.rb +1 -0
- data/lib/lutaml/xml/leptris.rb +47 -0
- data/lib/lutaml/xml/model_transform.rb +38 -14
- data/spec/lutaml/model/model_import_reentry_spec.rb +46 -0
- data/spec/lutaml/model/opal_smoke_spec.rb +17 -0
- data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +244 -0
- data/spec/lutaml/xml/opal_xml_spec.rb +47 -0
- data/spec/lutaml/xml/plan_namespaced_serialize_spec.rb +157 -0
- data/spec/lutaml/xml/plan_type_ns_attribute_spec.rb +2 -1
- data/spec/lutaml/xml/plan_wildcard_any_spec.rb +105 -0
- metadata +7 -2
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "XML plan fast path: map_any_element catch-all" do
|
|
6
|
+
# leptris#1552: the wildcard child row rides a two-pass walk where
|
|
7
|
+
# named rows take precedence; the hydrator bridges the unclaimed
|
|
8
|
+
# remainder in document order and casts it through the attribute —
|
|
9
|
+
# the interpretive pass's contract for map_any_element.
|
|
10
|
+
|
|
11
|
+
let(:host_class) do
|
|
12
|
+
klass = Class.new(Lutaml::Model::Serializable) do
|
|
13
|
+
attribute :title, :string
|
|
14
|
+
attribute :others, :string, collection: true
|
|
15
|
+
|
|
16
|
+
xml do
|
|
17
|
+
element "host"
|
|
18
|
+
map_element "title", to: :title
|
|
19
|
+
map_any_element to: :others
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
stub_const("Gate4Any::Host", klass)
|
|
23
|
+
klass
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
let(:typed_class) do
|
|
27
|
+
item = Class.new(Lutaml::Model::Serializable) do
|
|
28
|
+
attribute :content, :string
|
|
29
|
+
|
|
30
|
+
xml do
|
|
31
|
+
element "item"
|
|
32
|
+
map_content to: :content
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
stub_const("Gate4Any::Item", item)
|
|
36
|
+
model = Class.new(Lutaml::Model::Serializable) do
|
|
37
|
+
attribute :label, :string
|
|
38
|
+
attribute :items, Gate4Any::Item, collection: true
|
|
39
|
+
|
|
40
|
+
xml do
|
|
41
|
+
element "bag"
|
|
42
|
+
map_element "label", to: :label
|
|
43
|
+
map_any_element to: :items
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
stub_const("Gate4Any::Bag", model)
|
|
47
|
+
model
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
around do |example|
|
|
51
|
+
old = Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
52
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = true
|
|
53
|
+
Lutaml::Model::Config.with_adapter(xml: :leptris) { example.run }
|
|
54
|
+
ensure
|
|
55
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = old
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Members flow through the attribute's cast exactly as the
|
|
59
|
+
# interpretive pass does: String attributes stringify the wrapper
|
|
60
|
+
# (both paths identically), Serializable attributes build instances.
|
|
61
|
+
def member_shapes(elements)
|
|
62
|
+
elements.map { |e| e.class.name.split("::").last }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "captures unclaimed children in document order" do
|
|
66
|
+
doc = "<host><title>t</title><extra1>a</extra1>" \
|
|
67
|
+
"<extra2>b</extra2></host>"
|
|
68
|
+
|
|
69
|
+
parsed = host_class.from_xml(doc)
|
|
70
|
+
expect(parsed.title).to eq("t")
|
|
71
|
+
expect(parsed.others.size).to eq(2)
|
|
72
|
+
expect(member_shapes(parsed.others)).to eq(%w[String String])
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "captures typed members as model instances" do
|
|
76
|
+
doc = "<bag><label>L</label><item>one</item><item>two</item></bag>"
|
|
77
|
+
|
|
78
|
+
parsed = typed_class.from_xml(doc)
|
|
79
|
+
expect(parsed.label).to eq("L")
|
|
80
|
+
expect(parsed.items.map(&:content)).to eq(%w[one two])
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it "matches the interpretive path's capture" do
|
|
84
|
+
doc = "<host><title>t</title><extra1>a</extra1><extra2>b</extra2></host>"
|
|
85
|
+
|
|
86
|
+
interpretive = Lutaml::Model::Config.with_adapter(xml: :nokogiri) do
|
|
87
|
+
host_class.from_xml(doc)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
parsed = host_class.from_xml(doc)
|
|
91
|
+
expect(parsed.others.size).to eq(interpretive.others.size)
|
|
92
|
+
expect(member_shapes(parsed.others)).to eq(
|
|
93
|
+
member_shapes(interpretive.others).map { |n| n.sub("Nokogiri", "Leptris") },
|
|
94
|
+
)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "compiles under engines without wildcard rows to nil" do
|
|
98
|
+
allow(Lutaml::Xml::Leptris).to receive(:wildcard_rows_compatible?)
|
|
99
|
+
.and_return(false)
|
|
100
|
+
|
|
101
|
+
expect(Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
102
|
+
host_class, Lutaml::Model::Config.default_register
|
|
103
|
+
)).to be_nil
|
|
104
|
+
end
|
|
105
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.97
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-10-
|
|
11
|
+
date: 2026-10-08 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -207,6 +207,7 @@ files:
|
|
|
207
207
|
- docs/_guides/creating-xsd.adoc
|
|
208
208
|
- docs/_guides/custom-methods.adoc
|
|
209
209
|
- docs/_guides/document-validation.adoc
|
|
210
|
+
- docs/_guides/grammar-backed-formats.adoc
|
|
210
211
|
- docs/_guides/index.adoc
|
|
211
212
|
- docs/_guides/jsonld-serialization.adoc
|
|
212
213
|
- docs/_guides/keyvalue-serialization.adoc
|
|
@@ -1772,6 +1773,7 @@ files:
|
|
|
1772
1773
|
- spec/lutaml/model/mapping_rule_perf_guard_spec.rb
|
|
1773
1774
|
- spec/lutaml/model/mapping_type_validation_spec.rb
|
|
1774
1775
|
- spec/lutaml/model/mixed_content_spec.rb
|
|
1776
|
+
- spec/lutaml/model/model_import_reentry_spec.rb
|
|
1775
1777
|
- spec/lutaml/model/model_transformer_spec.rb
|
|
1776
1778
|
- spec/lutaml/model/multiple_mapping_spec.rb
|
|
1777
1779
|
- spec/lutaml/model/namespace_versioning_spec.rb
|
|
@@ -1811,6 +1813,7 @@ files:
|
|
|
1811
1813
|
- spec/lutaml/model/serializable_instantiate_spec.rb
|
|
1812
1814
|
- spec/lutaml/model/serializable_spec.rb
|
|
1813
1815
|
- spec/lutaml/model/serializable_validation_spec.rb
|
|
1816
|
+
- spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb
|
|
1814
1817
|
- spec/lutaml/model/serialize/builder_spec.rb
|
|
1815
1818
|
- spec/lutaml/model/serialize_perf_guard_spec.rb
|
|
1816
1819
|
- spec/lutaml/model/services/transformer_spec.rb
|
|
@@ -1986,10 +1989,12 @@ files:
|
|
|
1986
1989
|
- spec/lutaml/xml/pipeline_integration_spec.rb
|
|
1987
1990
|
- spec/lutaml/xml/plain_model_accessors_spec.rb
|
|
1988
1991
|
- spec/lutaml/xml/plan_fast_path_spec.rb
|
|
1992
|
+
- spec/lutaml/xml/plan_namespaced_serialize_spec.rb
|
|
1989
1993
|
- spec/lutaml/xml/plan_ns_less_document_spec.rb
|
|
1990
1994
|
- spec/lutaml/xml/plan_partition_spec.rb
|
|
1991
1995
|
- spec/lutaml/xml/plan_type_ns_attribute_spec.rb
|
|
1992
1996
|
- spec/lutaml/xml/plan_walk_spec.rb
|
|
1997
|
+
- spec/lutaml/xml/plan_wildcard_any_spec.rb
|
|
1993
1998
|
- spec/lutaml/xml/prefix_control_spec.rb
|
|
1994
1999
|
- spec/lutaml/xml/register_spec.rb
|
|
1995
2000
|
- spec/lutaml/xml/reusable_mapping_spec.rb
|