lutaml-model 0.8.5 → 0.8.6
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/.github/workflows/dependent-tests.yml +4 -1
- data/.rubocop_todo.yml +97 -22
- data/docs/_migrations/0-8-0-namespace-restructuring.adoc +90 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/adapter/adapter_helpers.rb +1 -42
- data/lib/lutaml/xml/adapter/base_adapter.rb +48 -458
- data/lib/lutaml/xml/adapter/namespace_data.rb +0 -17
- data/lib/lutaml/xml/adapter/namespace_uri_collector.rb +71 -0
- data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +5 -1110
- data/lib/lutaml/xml/adapter/oga_adapter.rb +6 -846
- data/lib/lutaml/xml/adapter/ox_adapter.rb +7 -884
- data/lib/lutaml/xml/adapter/plan_based_builder.rb +929 -0
- data/lib/lutaml/xml/adapter/rexml_adapter.rb +10 -864
- data/lib/lutaml/xml/adapter/xml_parser.rb +86 -0
- data/lib/lutaml/xml/adapter/xml_serializer.rb +291 -0
- data/lib/lutaml/xml/adapter.rb +0 -1
- data/lib/lutaml/xml/adapter_element.rb +7 -1
- data/lib/lutaml/xml/builder/base.rb +0 -1
- data/lib/lutaml/xml/data_model.rb +9 -1
- data/lib/lutaml/xml/document.rb +3 -1
- data/lib/lutaml/xml/element.rb +13 -10
- data/lib/lutaml/xml/serialization/format_conversion.rb +19 -42
- data/lib/lutaml/xml/serialization/instance_methods.rb +26 -35
- data/lib/lutaml/xml/transformation/custom_method_wrapper.rb +34 -55
- data/lib/lutaml/xml/transformation/rule_applier.rb +1 -1
- data/lib/lutaml/xml/xml_element.rb +24 -20
- data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +151 -0
- data/spec/lutaml/xml/adapter/order_spec.rb +150 -0
- data/spec/lutaml/xml/clear_parse_state_spec.rb +139 -0
- data/spec/lutaml/xml/doubly_defined_namespace_spec.rb +0 -2
- data/spec/lutaml/xml/schema/compiler_spec.rb +75 -69
- data/spec/lutaml/xml/transformation/custom_method_wrapper_spec.rb +213 -14
- metadata +9 -3
- data/lib/lutaml/xml/adapter/xml_serialization.rb +0 -145
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c356719b1c0c3434ba1acb3f59be81cb9374403c8020710ee4d4a5ea78748765
|
|
4
|
+
data.tar.gz: ac2aa51ef80ce8db3c50b8055df95b6a3732e3e40b72689c635e8ac22fe889f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b63ac862dc2eeef4a599ff5ada8c6f2434b3bf71187b5813a2637e69f25170692d373bffb2b9413b48323b1cd6161a8529a2ec6582a2fc313d46c95fa8b67088
|
|
7
|
+
data.tar.gz: 24e23bdedad47cc0796cff0bad1b32809c649bad4a13a64b23d08b3bef2dad4c769cfc299cdb85abeffd9a53ea677c41f91c759114f320a5047787cafc6c253e
|
|
@@ -19,8 +19,11 @@ on:
|
|
|
19
19
|
|
|
20
20
|
jobs:
|
|
21
21
|
rake:
|
|
22
|
-
uses: metanorma/ci/.github/workflows/dependent-rake.yml@
|
|
22
|
+
uses: metanorma/ci/.github/workflows/dependent-rake.yml@main
|
|
23
23
|
with:
|
|
24
24
|
command: bundle exec rspec
|
|
25
|
+
setup-tools: 'inkscape,ghostscript,exiftool,ffmpeg,imagemagick'
|
|
26
|
+
after-setup-ruby: |
|
|
27
|
+
if [ -f frontend/package.json ]; then cd frontend && npm install && npm run build; fi
|
|
25
28
|
secrets:
|
|
26
29
|
pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2026-05-
|
|
3
|
+
# on 2026-05-13 07:30:26 UTC using RuboCop version 1.86.0.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
@@ -11,13 +11,67 @@ Gemspec/RequiredRubyVersion:
|
|
|
11
11
|
Exclude:
|
|
12
12
|
- 'lutaml-model.gemspec'
|
|
13
13
|
|
|
14
|
-
# Offense count:
|
|
14
|
+
# Offense count: 4
|
|
15
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
16
|
+
# Configuration parameters: EnforcedStyle, IndentationWidth.
|
|
17
|
+
# SupportedStyles: with_first_argument, with_fixed_indentation
|
|
18
|
+
Layout/ArgumentAlignment:
|
|
19
|
+
Exclude:
|
|
20
|
+
- 'lib/lutaml/xml/adapter/plan_based_builder.rb'
|
|
21
|
+
- 'lib/lutaml/xml/adapter/xml_parser.rb'
|
|
22
|
+
- 'lib/lutaml/xml/serialization/instance_methods.rb'
|
|
23
|
+
- 'spec/lutaml/xml/schema/compiler_spec.rb'
|
|
24
|
+
|
|
25
|
+
# Offense count: 1
|
|
26
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
27
|
+
# Configuration parameters: IndentationWidth.
|
|
28
|
+
Layout/AssignmentIndentation:
|
|
29
|
+
Exclude:
|
|
30
|
+
- 'lib/lutaml/xml/adapter/xml_serializer.rb'
|
|
31
|
+
|
|
32
|
+
# Offense count: 3
|
|
33
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
34
|
+
# Configuration parameters: EnforcedStyleAlignWith.
|
|
35
|
+
# SupportedStylesAlignWith: either, start_of_block, start_of_line
|
|
36
|
+
Layout/BlockAlignment:
|
|
37
|
+
Exclude:
|
|
38
|
+
- 'lib/lutaml/xml/serialization/format_conversion.rb'
|
|
39
|
+
- 'lib/lutaml/xml/xml_element.rb'
|
|
40
|
+
|
|
41
|
+
# Offense count: 3
|
|
42
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
43
|
+
Layout/BlockEndNewline:
|
|
44
|
+
Exclude:
|
|
45
|
+
- 'lib/lutaml/xml/serialization/format_conversion.rb'
|
|
46
|
+
- 'lib/lutaml/xml/xml_element.rb'
|
|
47
|
+
|
|
48
|
+
# Offense count: 6
|
|
49
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
50
|
+
# Configuration parameters: Width, EnforcedStyleAlignWith, AllowedPatterns.
|
|
51
|
+
# SupportedStylesAlignWith: start_of_line, relative_to_receiver
|
|
52
|
+
Layout/IndentationWidth:
|
|
53
|
+
Exclude:
|
|
54
|
+
- 'lib/lutaml/xml/serialization/format_conversion.rb'
|
|
55
|
+
- 'lib/lutaml/xml/xml_element.rb'
|
|
56
|
+
|
|
57
|
+
# Offense count: 2981
|
|
15
58
|
# This cop supports safe autocorrection (--autocorrect).
|
|
16
59
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, AllowQualifiedName, URISchemes, AllowRBSInlineAnnotation, AllowCopDirectives, AllowedPatterns, SplitStrings.
|
|
17
60
|
# URISchemes: http, https
|
|
18
61
|
Layout/LineLength:
|
|
19
62
|
Enabled: false
|
|
20
63
|
|
|
64
|
+
# Offense count: 5
|
|
65
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
66
|
+
# Configuration parameters: AllowInHeredoc.
|
|
67
|
+
Layout/TrailingWhitespace:
|
|
68
|
+
Exclude:
|
|
69
|
+
- 'lib/lutaml/xml/adapter/plan_based_builder.rb'
|
|
70
|
+
- 'lib/lutaml/xml/adapter/xml_parser.rb'
|
|
71
|
+
- 'lib/lutaml/xml/adapter/xml_serializer.rb'
|
|
72
|
+
- 'lib/lutaml/xml/serialization/instance_methods.rb'
|
|
73
|
+
- 'spec/lutaml/xml/schema/compiler_spec.rb'
|
|
74
|
+
|
|
21
75
|
# Offense count: 21
|
|
22
76
|
# Configuration parameters: AllowedMethods.
|
|
23
77
|
# AllowedMethods: enums
|
|
@@ -34,10 +88,16 @@ Lint/ConstantDefinitionInBlock:
|
|
|
34
88
|
Lint/DuplicateBranch:
|
|
35
89
|
Enabled: false
|
|
36
90
|
|
|
37
|
-
# Offense count:
|
|
91
|
+
# Offense count: 22
|
|
38
92
|
Lint/DuplicateMethods:
|
|
39
93
|
Exclude:
|
|
40
94
|
- 'lib/lutaml/xml/mapping.rb'
|
|
95
|
+
- 'spec/lutaml/model/liquid_compatibility_spec.rb'
|
|
96
|
+
- 'spec/lutaml/xml/namespace_no_hoisting_spec.rb'
|
|
97
|
+
- 'spec/lutaml/xml/namespace_scope_declare_spec.rb'
|
|
98
|
+
- 'spec/lutaml/xml/namespace_scope_vcard_spec.rb'
|
|
99
|
+
- 'spec/lutaml/xml/prefix_control_spec.rb'
|
|
100
|
+
- 'spec/lutaml/xml/type_namespace_examples_spec.rb'
|
|
41
101
|
|
|
42
102
|
# Offense count: 1
|
|
43
103
|
# This cop supports safe autocorrection (--autocorrect).
|
|
@@ -90,13 +150,12 @@ Lint/StructNewOverride:
|
|
|
90
150
|
Exclude:
|
|
91
151
|
- 'lib/lutaml/model/import_registry.rb'
|
|
92
152
|
|
|
93
|
-
# Offense count:
|
|
153
|
+
# Offense count: 14
|
|
94
154
|
# This cop supports safe autocorrection (--autocorrect).
|
|
95
155
|
# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods, IgnoreNotImplementedMethods, NotImplementedExceptions.
|
|
96
156
|
# NotImplementedExceptions: NotImplementedError
|
|
97
157
|
Lint/UnusedMethodArgument:
|
|
98
158
|
Exclude:
|
|
99
|
-
- 'lib/lutaml/xml/adapter/nokogiri_adapter.rb'
|
|
100
159
|
- 'lib/lutaml/xml/declaration_planner.rb'
|
|
101
160
|
- 'lib/lutaml/xml/mapping.rb'
|
|
102
161
|
- 'lib/lutaml/xml/namespace_collector.rb'
|
|
@@ -104,45 +163,44 @@ Lint/UnusedMethodArgument:
|
|
|
104
163
|
- 'lib/lutaml/xml/unqualified_inheritance_strategy.rb'
|
|
105
164
|
- 'spec/support/xml/xsd/code_example_validator.rb'
|
|
106
165
|
|
|
107
|
-
# Offense count:
|
|
166
|
+
# Offense count: 1
|
|
108
167
|
Lint/UselessConstantScoping:
|
|
109
168
|
Exclude:
|
|
110
|
-
- 'lib/lutaml/xml/adapter/nokogiri_adapter.rb'
|
|
111
169
|
- 'lib/lutaml/xml/mapping_rule.rb'
|
|
112
170
|
|
|
113
|
-
# Offense count:
|
|
171
|
+
# Offense count: 342
|
|
114
172
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
115
173
|
Metrics/AbcSize:
|
|
116
174
|
Enabled: false
|
|
117
175
|
|
|
118
|
-
# Offense count:
|
|
176
|
+
# Offense count: 39
|
|
119
177
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
|
120
178
|
# AllowedMethods: refine
|
|
121
179
|
Metrics/BlockLength:
|
|
122
180
|
Max: 127
|
|
123
181
|
|
|
124
|
-
# Offense count:
|
|
182
|
+
# Offense count: 16
|
|
125
183
|
# Configuration parameters: CountBlocks, CountModifierForms.
|
|
126
184
|
Metrics/BlockNesting:
|
|
127
185
|
Max: 6
|
|
128
186
|
|
|
129
|
-
# Offense count:
|
|
187
|
+
# Offense count: 300
|
|
130
188
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
131
189
|
Metrics/CyclomaticComplexity:
|
|
132
190
|
Enabled: false
|
|
133
191
|
|
|
134
|
-
# Offense count:
|
|
192
|
+
# Offense count: 549
|
|
135
193
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
|
136
194
|
Metrics/MethodLength:
|
|
137
195
|
Max: 514
|
|
138
196
|
|
|
139
|
-
# Offense count:
|
|
197
|
+
# Offense count: 81
|
|
140
198
|
# Configuration parameters: CountKeywordArgs.
|
|
141
199
|
Metrics/ParameterLists:
|
|
142
200
|
Max: 24
|
|
143
201
|
MaxOptionalParameters: 5
|
|
144
202
|
|
|
145
|
-
# Offense count:
|
|
203
|
+
# Offense count: 251
|
|
146
204
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
147
205
|
Metrics/PerceivedComplexity:
|
|
148
206
|
Enabled: false
|
|
@@ -234,7 +292,7 @@ RSpec/BeforeAfterAll:
|
|
|
234
292
|
RSpec/ContextWording:
|
|
235
293
|
Enabled: false
|
|
236
294
|
|
|
237
|
-
# Offense count:
|
|
295
|
+
# Offense count: 94
|
|
238
296
|
# Configuration parameters: IgnoredMetadata.
|
|
239
297
|
RSpec/DescribeClass:
|
|
240
298
|
Enabled: false
|
|
@@ -245,7 +303,7 @@ RSpec/DescribeMethod:
|
|
|
245
303
|
- 'spec/lutaml/xml/schema/xsd/schema_helper_methods_spec.rb'
|
|
246
304
|
- 'spec/lutaml/xml/serializable_namespace_spec.rb'
|
|
247
305
|
|
|
248
|
-
# Offense count:
|
|
306
|
+
# Offense count: 1238
|
|
249
307
|
# Configuration parameters: CountAsOne.
|
|
250
308
|
RSpec/ExampleLength:
|
|
251
309
|
Max: 68
|
|
@@ -320,7 +378,7 @@ RSpec/MultipleDescribes:
|
|
|
320
378
|
- 'spec/lutaml/xml/namespace_resolution_strategy_spec.rb'
|
|
321
379
|
- 'spec/lutaml/xml/xml_space_type_spec.rb'
|
|
322
380
|
|
|
323
|
-
# Offense count:
|
|
381
|
+
# Offense count: 1468
|
|
324
382
|
RSpec/MultipleExpectations:
|
|
325
383
|
Max: 21
|
|
326
384
|
|
|
@@ -344,7 +402,7 @@ RSpec/NoExpectationExample:
|
|
|
344
402
|
- 'spec/lutaml/model/global_context_spec.rb'
|
|
345
403
|
- 'spec/lutaml/model/type_context_spec.rb'
|
|
346
404
|
|
|
347
|
-
# Offense count:
|
|
405
|
+
# Offense count: 10
|
|
348
406
|
RSpec/RemoveConst:
|
|
349
407
|
Exclude:
|
|
350
408
|
- 'spec/lutaml/xml/schema/compiler_spec.rb'
|
|
@@ -393,6 +451,18 @@ Security/MarshalLoad:
|
|
|
393
451
|
Exclude:
|
|
394
452
|
- 'scripts-xmi-profile/profile_xmi.rb'
|
|
395
453
|
|
|
454
|
+
# Offense count: 4
|
|
455
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
456
|
+
# Configuration parameters: EnforcedStyle, ProceduralMethods, FunctionalMethods, AllowedMethods, AllowedPatterns, AllowBracesOnProceduralOneLiners, BracesRequiredMethods.
|
|
457
|
+
# SupportedStyles: line_count_based, semantic, braces_for_chaining, always_braces
|
|
458
|
+
# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object
|
|
459
|
+
# FunctionalMethods: let, let!, subject, watch
|
|
460
|
+
# AllowedMethods: lambda, proc, it
|
|
461
|
+
Style/BlockDelimiters:
|
|
462
|
+
Exclude:
|
|
463
|
+
- 'lib/lutaml/xml/serialization/format_conversion.rb'
|
|
464
|
+
- 'lib/lutaml/xml/xml_element.rb'
|
|
465
|
+
|
|
396
466
|
# Offense count: 2
|
|
397
467
|
# This cop supports unsafe autocorrection (--autocorrect-all).
|
|
398
468
|
# Configuration parameters: AllowedMethods, AllowedPatterns.
|
|
@@ -402,7 +472,7 @@ Style/ClassEqualityComparison:
|
|
|
402
472
|
- 'lib/lutaml/model/attribute.rb'
|
|
403
473
|
- 'lib/lutaml/model/validation/profile.rb'
|
|
404
474
|
|
|
405
|
-
# Offense count:
|
|
475
|
+
# Offense count: 7
|
|
406
476
|
# This cop supports safe autocorrection (--autocorrect).
|
|
407
477
|
# Configuration parameters: EnforcedStyle, AllowComments.
|
|
408
478
|
# SupportedStyles: empty, nil, both
|
|
@@ -411,9 +481,6 @@ Style/EmptyElse:
|
|
|
411
481
|
- 'lib/lutaml/key_value/data_model/element.rb'
|
|
412
482
|
- 'lib/lutaml/key_value/transformation.rb'
|
|
413
483
|
- 'lib/lutaml/model/mapping/mapping_rule.rb'
|
|
414
|
-
- 'lib/lutaml/xml/adapter/nokogiri_adapter.rb'
|
|
415
|
-
- 'lib/lutaml/xml/adapter/oga_adapter.rb'
|
|
416
|
-
- 'lib/lutaml/xml/adapter/ox_adapter.rb'
|
|
417
484
|
- 'lib/lutaml/xml/declaration_planner.rb'
|
|
418
485
|
- 'lib/lutaml/xml/model_transform.rb'
|
|
419
486
|
|
|
@@ -441,6 +508,14 @@ Style/MixinUsage:
|
|
|
441
508
|
- 'bench/bench_unitsml.rb'
|
|
442
509
|
- 'bench/bench_xmi.rb'
|
|
443
510
|
|
|
511
|
+
# Offense count: 3
|
|
512
|
+
# This cop supports safe autocorrection (--autocorrect).
|
|
513
|
+
Style/MultilineIfModifier:
|
|
514
|
+
Exclude:
|
|
515
|
+
- 'lib/lutaml/xml/adapter/xml_parser.rb'
|
|
516
|
+
- 'lib/lutaml/xml/adapter/xml_serializer.rb'
|
|
517
|
+
- 'spec/lutaml/xml/schema/compiler_spec.rb'
|
|
518
|
+
|
|
444
519
|
# Offense count: 12
|
|
445
520
|
# Configuration parameters: AllowedClasses.
|
|
446
521
|
Style/OneClassPerFile:
|
|
@@ -873,6 +873,96 @@ xml do
|
|
|
873
873
|
end
|
|
874
874
|
----
|
|
875
875
|
|
|
876
|
+
== Custom XML Serialization Methods
|
|
877
|
+
|
|
878
|
+
Custom XML methods declared via `with: { from: :foo_from_xml, to: :foo_to_xml }` continue to work in v0.8.0, but the runtime objects passed to them have changed. This section covers the API differences and the migration steps needed.
|
|
879
|
+
|
|
880
|
+
=== `doc` is now a `CustomMethodWrapper`
|
|
881
|
+
|
|
882
|
+
In v0.7.x the third argument of `def foo_to_xml(model, parent, doc)` was the underlying adapter document (Nokogiri-, Ox-, Oga-, REXML-backed). In v0.8.0 it is a `Lutaml::Xml::CustomMethodWrapper`, and `parent` is a `Lutaml::Xml::DataModel::XmlElement` rather than an adapter element. The wrapper exposes the same `create_element` / `add_text` / `add_attribute` / `add_element` surface, so straight-line code that uses only those methods keeps working.
|
|
883
|
+
|
|
884
|
+
=== `add_element(parent, x)` raises `TypeError` for foreign element types
|
|
885
|
+
|
|
886
|
+
`doc.add_element(parent, x)` accepts two shapes for `x`:
|
|
887
|
+
|
|
888
|
+
* A `String`, parsed as an XML fragment via Moxml and grafted in as `DataModel::XmlElement` children. This is the path most existing custom methods rely on (e.g. passing the result of `instance.to_xml`).
|
|
889
|
+
* A `Lutaml::Xml::DataModel::XmlElement`, added directly as a child.
|
|
890
|
+
|
|
891
|
+
Anything else — most commonly a `Nokogiri::XML::Element` left over from a v0.7-style custom method that built fragments with `Nokogiri::XML::Builder` — now raises a `TypeError` with a message like:
|
|
892
|
+
|
|
893
|
+
add_element expects a String or XmlElement, got Nokogiri::XML::Element.
|
|
894
|
+
Call .to_xml on the element first.
|
|
895
|
+
|
|
896
|
+
==== Fix
|
|
897
|
+
|
|
898
|
+
Serialize the foreign element to a string before handing it to the wrapper:
|
|
899
|
+
|
|
900
|
+
[source,ruby]
|
|
901
|
+
----
|
|
902
|
+
# v0.7-era pattern (works against Nokogiri-backed adapter doc, raises in 0.8)
|
|
903
|
+
b.parent.elements.first.elements.each { |x| doc.add_element(parent, x) }
|
|
904
|
+
|
|
905
|
+
# v0.8 fix — pass the string fragment, takes the Moxml path
|
|
906
|
+
b.parent.elements.first.elements.each { |x| doc.add_element(parent, x.to_xml) }
|
|
907
|
+
----
|
|
908
|
+
|
|
909
|
+
The same applies to single-element handoffs:
|
|
910
|
+
|
|
911
|
+
[source,ruby]
|
|
912
|
+
----
|
|
913
|
+
# v0.7-era
|
|
914
|
+
elem = b.parent.elements.first
|
|
915
|
+
doc.add_element(parent, elem)
|
|
916
|
+
|
|
917
|
+
# v0.8 fix
|
|
918
|
+
elem = b.parent.elements.first.to_xml
|
|
919
|
+
doc.add_element(parent, elem)
|
|
920
|
+
----
|
|
921
|
+
|
|
922
|
+
=== Sibling walks: `parent.elements` → `current_context.children`
|
|
923
|
+
|
|
924
|
+
Custom methods that introspect the document under construction — for example, an idempotency guard that checks whether a sibling element has already been emitted — need to be translated. The v0.7 idiom
|
|
925
|
+
|
|
926
|
+
[source,ruby]
|
|
927
|
+
----
|
|
928
|
+
def already_emitted?(doc)
|
|
929
|
+
doc.parent.elements.detect { |x| x.name == "foo" }
|
|
930
|
+
end
|
|
931
|
+
----
|
|
932
|
+
|
|
933
|
+
becomes
|
|
934
|
+
|
|
935
|
+
[source,ruby]
|
|
936
|
+
----
|
|
937
|
+
def already_emitted?(doc)
|
|
938
|
+
doc.current_context.children.detect { |x| x.name == "foo" }
|
|
939
|
+
end
|
|
940
|
+
----
|
|
941
|
+
|
|
942
|
+
If you need to support both v0.7 and v0.8 from the same codebase, use a version constant rather than `respond_to?` checks:
|
|
943
|
+
|
|
944
|
+
[source,ruby]
|
|
945
|
+
----
|
|
946
|
+
def already_emitted?(doc)
|
|
947
|
+
siblings = if defined?(Lutaml::VERSION) && Gem::Version.new(Lutaml::VERSION) >= Gem::Version.new("0.8")
|
|
948
|
+
doc.current_context.children
|
|
949
|
+
else
|
|
950
|
+
doc.parent.elements
|
|
951
|
+
end
|
|
952
|
+
siblings.detect { |x| x.name == "foo" }
|
|
953
|
+
end
|
|
954
|
+
----
|
|
955
|
+
|
|
956
|
+
=== Migration checklist for custom methods
|
|
957
|
+
|
|
958
|
+
Audit each `with: { to: :*_to_xml }` method for the following patterns:
|
|
959
|
+
|
|
960
|
+
. Does it call `Nokogiri::XML::Builder.new`, `Ox.dump`, or any other adapter-specific builder, then pass the resulting elements to `doc.add_element`? → Convert each element to a string via `.to_xml` (or equivalent) before passing.
|
|
961
|
+
. Does it walk `doc.parent.elements` / `doc.parent.children`? → Translate to `doc.current_context.children`.
|
|
962
|
+
. Does it cast `doc` to a specific adapter type, or call adapter-specific methods on it? → Replace with the wrapper API (`create_element`, `add_text`, `add_attribute`, `add_element`).
|
|
963
|
+
|
|
964
|
+
Test by round-tripping a representative fixture through `Model.from_xml(file).to_xml` and asserting equivalence. Foreign types will now raise `TypeError` rather than being silently dropped.
|
|
965
|
+
|
|
876
966
|
== Testing Your Migration
|
|
877
967
|
|
|
878
968
|
After updating, run your test suite:
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -29,7 +29,7 @@ module Lutaml
|
|
|
29
29
|
when Moxml::Cdata
|
|
30
30
|
"#cdata-section"
|
|
31
31
|
when Moxml::ProcessingInstruction
|
|
32
|
-
|
|
32
|
+
element.target
|
|
33
33
|
when Moxml::Comment
|
|
34
34
|
"comment"
|
|
35
35
|
else
|
|
@@ -102,47 +102,6 @@ module Lutaml
|
|
|
102
102
|
def text_node?(node)
|
|
103
103
|
TEXT_CLASSES.include?(node.class)
|
|
104
104
|
end
|
|
105
|
-
|
|
106
|
-
# Build Element object from child node
|
|
107
|
-
#
|
|
108
|
-
# @param child [Moxml::Node] The child node
|
|
109
|
-
# @return [Element] The Element object
|
|
110
|
-
def build_element_from_child(child)
|
|
111
|
-
if text_node?(child)
|
|
112
|
-
Element.new("Text", "text", node_type: :text)
|
|
113
|
-
else
|
|
114
|
-
Element.new("Element", name_of(child), node_type: :element)
|
|
115
|
-
end
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
# Get the prefix for a namespace URI from hoisted declarations
|
|
119
|
-
#
|
|
120
|
-
# This checks if a namespace URI is already declared in hoisted_declarations
|
|
121
|
-
# and returns the prefix that should be used. This prevents duplicate xmlns
|
|
122
|
-
# declarations when both hoisted_declarations and attribute code try to add
|
|
123
|
-
# the same namespace.
|
|
124
|
-
#
|
|
125
|
-
# @param namespace_uri [String] The namespace URI to look up
|
|
126
|
-
# @param hoisted_declarations [Hash{String, nil => String}] The hoisted declarations
|
|
127
|
-
# (keys are prefixes or nil for default, values are URIs)
|
|
128
|
-
# @return [String, nil] The prefix if found, nil if not hoisted
|
|
129
|
-
def prefix_for_namespace_uri(namespace_uri, hoisted_declarations)
|
|
130
|
-
return nil unless hoisted_declarations
|
|
131
|
-
|
|
132
|
-
hoisted_declarations.each do |prefix, uri|
|
|
133
|
-
return prefix if uri == namespace_uri
|
|
134
|
-
end
|
|
135
|
-
nil
|
|
136
|
-
end
|
|
137
|
-
|
|
138
|
-
# Check if a namespace URI is already hoisted
|
|
139
|
-
#
|
|
140
|
-
# @param namespace_uri [String] The namespace URI to check
|
|
141
|
-
# @param hoisted_declarations [Hash{String, nil => String}] The hoisted declarations
|
|
142
|
-
# @return [Boolean] true if the namespace is already hoisted
|
|
143
|
-
def namespace_uri_hoisted?(namespace_uri, hoisted_declarations)
|
|
144
|
-
prefix_for_namespace_uri(namespace_uri, hoisted_declarations) != nil
|
|
145
|
-
end
|
|
146
105
|
end
|
|
147
106
|
end
|
|
148
107
|
end
|