lutaml-model 0.8.11 → 0.8.13

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.
Files changed (149) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/opal.yml +31 -0
  3. data/.rspec-opal +5 -0
  4. data/.rubocop_todo.yml +45 -34
  5. data/README.adoc +126 -104
  6. data/RELEASE_NOTES.adoc +3 -3
  7. data/benchmark/quick_benchmark.rb +2 -2
  8. data/benchmark/serialization_benchmark.rb +4 -4
  9. data/docs/_guides/advanced-mapping.adoc +1 -1
  10. data/docs/_guides/character-encoding.adoc +3 -3
  11. data/docs/_guides/index.adoc +4 -0
  12. data/docs/_guides/missing-values-handling.adoc +6 -6
  13. data/docs/_guides/ooxml-examples.adoc +7 -7
  14. data/docs/_guides/opal.adoc +221 -0
  15. data/docs/_guides/value-transformations.adoc +7 -7
  16. data/docs/_guides/xml/namespace-presentation.adoc +1 -1
  17. data/docs/_guides/xml/namespace-semantics.adoc +15 -15
  18. data/docs/_guides/xml/type-namespaces.adoc +9 -9
  19. data/docs/_guides/xml-mapping.adoc +32 -26
  20. data/docs/_guides/xml-namespace-qualification.adoc +4 -4
  21. data/docs/_guides/xml-namespaces.adoc +2 -2
  22. data/docs/_guides/xml_mappings/04_xml_namespace_class.adoc +18 -18
  23. data/docs/_guides/xml_mappings/05_common_patterns.adoc +16 -16
  24. data/docs/_guides/xml_mappings/06_migration_guide.adoc +5 -5
  25. data/docs/_guides/xml_mappings/07_best_practices.adoc +13 -12
  26. data/docs/_migrations/0-8-0-namespace-restructuring.adoc +2 -2
  27. data/docs/_pages/attributes.adoc +2 -2
  28. data/docs/_pages/collections.adoc +26 -20
  29. data/docs/_pages/configuration.adoc +9 -4
  30. data/docs/_pages/consolidation-mapping.adoc +4 -4
  31. data/docs/_pages/importable_models.adoc +14 -13
  32. data/docs/_pages/index.adoc +1 -0
  33. data/docs/_pages/quick-start.adoc +1 -1
  34. data/docs/_pages/serialization_adapters.adoc +3 -2
  35. data/docs/_pages/value_types.adoc +10 -10
  36. data/docs/_references/custom_registers.adoc +7 -7
  37. data/docs/_references/format-independent-features.adoc +4 -4
  38. data/docs/_references/instance-serialization.adoc +1 -1
  39. data/docs/_references/parent-root-context.adoc +3 -3
  40. data/docs/_tutorials/basic-model-definition.adoc +1 -1
  41. data/docs/_tutorials/first-xml-serialization.adoc +4 -4
  42. data/docs/_tutorials/lutaml-xml-architecture.adoc +4 -4
  43. data/docs/_tutorials/validation-basics.adoc +1 -1
  44. data/docs/_tutorials/working-with-collections.adoc +2 -2
  45. data/docs/_tutorials/xml-namespaces-basics.adoc +1 -1
  46. data/docs/_tutorials/xml-schema-primer-style-guide.adoc +29 -29
  47. data/docs/cli_compare.adoc +1 -1
  48. data/docs/index.adoc +2 -1
  49. data/docs/namespace-management.adoc +14 -14
  50. data/lib/lutaml/hash_format/adapter/mapping.rb +2 -4
  51. data/lib/lutaml/json/adapter/mapping.rb +2 -4
  52. data/lib/lutaml/jsonl/adapter/mapping.rb +2 -4
  53. data/lib/lutaml/key_value/adapter/hash/mapping.rb +2 -4
  54. data/lib/lutaml/key_value/adapter/json/mapping.rb +2 -4
  55. data/lib/lutaml/key_value/adapter/jsonl/mapping.rb +2 -4
  56. data/lib/lutaml/key_value/adapter/toml/mapping.rb +2 -4
  57. data/lib/lutaml/key_value/adapter/yaml/mapping.rb +2 -4
  58. data/lib/lutaml/key_value/adapter/yamls/mapping.rb +2 -4
  59. data/lib/lutaml/key_value/mapping.rb +35 -10
  60. data/lib/lutaml/model/adapter_resolver.rb +5 -8
  61. data/lib/lutaml/model/collection.rb +11 -11
  62. data/lib/lutaml/model/error/no_root_mapping_error.rb +6 -5
  63. data/lib/lutaml/model/error/no_root_namespace_error.rb +6 -5
  64. data/lib/lutaml/model/error/type_only_mapping_error.rb +13 -0
  65. data/lib/lutaml/model/error/type_only_namespace_error.rb +12 -0
  66. data/lib/lutaml/model/mapping/mapping.rb +12 -0
  67. data/lib/lutaml/model/version.rb +1 -1
  68. data/lib/lutaml/model.rb +3 -0
  69. data/lib/lutaml/toml/adapter/mapping.rb +2 -4
  70. data/lib/lutaml/xml/adapter/base_adapter.rb +0 -9
  71. data/lib/lutaml/xml/adapter/nokogiri_adapter.rb +0 -1
  72. data/lib/lutaml/xml/adapter/oga_adapter.rb +0 -1
  73. data/lib/lutaml/xml/adapter/ox_adapter.rb +0 -1
  74. data/lib/lutaml/xml/adapter/rexml_adapter.rb +0 -1
  75. data/lib/lutaml/xml/adapter/xml_serializer.rb +42 -22
  76. data/lib/lutaml/xml/adapter.rb +4 -0
  77. data/lib/lutaml/xml/builder/base.rb +64 -25
  78. data/lib/lutaml/xml/builder/nokogiri.rb +0 -2
  79. data/lib/lutaml/xml/builder/oga.rb +0 -2
  80. data/lib/lutaml/xml/builder/ox.rb +0 -2
  81. data/lib/lutaml/xml/builder/rexml.rb +0 -2
  82. data/lib/lutaml/xml/builder.rb +1 -0
  83. data/lib/lutaml/xml/configurable.rb +2 -2
  84. data/lib/lutaml/xml/declaration_handler.rb +3 -105
  85. data/lib/lutaml/xml/mapping.rb +3 -3
  86. data/lib/lutaml/xml/schema/xsd/documentation.rb +1 -1
  87. data/lib/lutaml/xml/schema/xsd.rb +5 -4
  88. data/lib/lutaml/xml/schema.rb +8 -5
  89. data/lib/lutaml/xml/serialization/collection_ext.rb +7 -7
  90. data/lib/lutaml/xml/serialization/format_conversion.rb +1 -1
  91. data/lib/lutaml/xml/serialization/instance_methods.rb +1 -1
  92. data/lib/lutaml/xml/xml_orderable.rb +17 -0
  93. data/lib/lutaml/xml.rb +9 -13
  94. data/lib/lutaml/yaml/adapter/mapping.rb +2 -4
  95. data/lib/lutaml/yamls/adapter/mapping.rb +7 -3
  96. data/lib/tasks/memory_profile.rb +2 -2
  97. data/lib/tasks/performance_benchmark.rb +5 -5
  98. data/lutaml-model.gemspec +1 -1
  99. data/spec/lutaml/key_value/transformation/rule_compiler_spec.rb +1 -1
  100. data/spec/lutaml/key_value/transformation/value_serializer_spec.rb +1 -1
  101. data/spec/lutaml/model/attribute_collection_spec.rb +1 -1
  102. data/spec/lutaml/model/cli_spec.rb +1 -1
  103. data/spec/lutaml/model/collection_spec.rb +1 -1
  104. data/spec/lutaml/model/collection_validation_spec.rb +6 -6
  105. data/spec/lutaml/model/consolidation_spec.rb +8 -8
  106. data/spec/lutaml/model/custom_collection_spec.rb +3 -3
  107. data/spec/lutaml/model/default_register_spec.rb +23 -23
  108. data/spec/lutaml/model/delegation_spec.rb +3 -10
  109. data/spec/lutaml/model/derived_attribute_serialization_spec.rb +1 -1
  110. data/spec/lutaml/model/dynamic_attribute_spec.rb +2 -2
  111. data/spec/lutaml/model/enum_spec.rb +1 -1
  112. data/spec/lutaml/model/group_spec.rb +12 -12
  113. data/spec/lutaml/model/lazy_collection_spec.rb +4 -4
  114. data/spec/lutaml/model/mixed_content_spec.rb +2 -2
  115. data/spec/lutaml/model/namespace_versioning_spec.rb +4 -4
  116. data/spec/lutaml/model/opal_smoke_spec.rb +117 -0
  117. data/spec/lutaml/model/processing_instruction_spec.rb +11 -11
  118. data/spec/lutaml/model/register_methods_spec.rb +2 -2
  119. data/spec/lutaml/model/render_empty_spec.rb +1 -1
  120. data/spec/lutaml/model/serialize_perf_guard_spec.rb +1 -1
  121. data/spec/lutaml/model/transform_dynamic_attributes_spec.rb +1 -1
  122. data/spec/lutaml/model/transformation_builder_spec.rb +2 -2
  123. data/spec/lutaml/model/xml_decoupling_spec.rb +3 -3
  124. data/spec/lutaml/model/xsd_patterns_spec.rb +2 -3
  125. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  126. data/spec/lutaml/xml/clear_parse_state_spec.rb +1 -1
  127. data/spec/lutaml/xml/content_model_validation_spec.rb +4 -2
  128. data/spec/lutaml/xml/doubly_defined_namespace_spec.rb +5 -5
  129. data/spec/lutaml/xml/enhanced_mapping_spec.rb +2 -1
  130. data/spec/lutaml/xml/entity_fragmentation_spec.rb +5 -5
  131. data/spec/lutaml/xml/indent_spec.rb +109 -0
  132. data/spec/lutaml/xml/line_ending_spec.rb +66 -0
  133. data/spec/lutaml/xml/mapping_finalization_guard_spec.rb +2 -2
  134. data/spec/lutaml/xml/model_transform_guard_spec.rb +4 -4
  135. data/spec/lutaml/xml/namespace_alias_spec.rb +4 -4
  136. data/spec/lutaml/xml/namespace_aware_parsing_spec.rb +3 -3
  137. data/spec/lutaml/xml/namespace_bound_element_roundtrip_spec.rb +2 -2
  138. data/spec/lutaml/xml/namespace_format_preservation_spec.rb +1 -1
  139. data/spec/lutaml/xml/namespace_inheritance_spec.rb +3 -3
  140. data/spec/lutaml/xml/namespace_preservation_spec.rb +5 -5
  141. data/spec/lutaml/xml/opal_xml_spec.rb +145 -0
  142. data/spec/lutaml/xml/pipeline_integration_spec.rb +145 -0
  143. data/spec/lutaml/xml/schema_primer_spec.rb +5 -5
  144. data/spec/lutaml/xml/transformation_spec.rb +20 -20
  145. data/spec/lutaml/xml/type_namespace/collector_spec.rb +1 -1
  146. data/spec/lutaml/xml/type_namespace/planner_spec.rb +3 -3
  147. data/spec/lutaml/xml/xml_spec.rb +64 -13
  148. data/spec/support/opal.rb +6 -0
  149. metadata +16 -4
@@ -66,7 +66,7 @@ module CustomCollection
66
66
  end
67
67
 
68
68
  key_value do
69
- root "items"
69
+ key "items"
70
70
  map_instances to: :items
71
71
  end
72
72
  end
@@ -138,7 +138,7 @@ module CustomCollection
138
138
  end
139
139
 
140
140
  key_value do
141
- root "items"
141
+ key "items"
142
142
  map "items", to: :items, value_map: {
143
143
  from: { empty: :empty, omitted: :omitted, nil: :nil },
144
144
  to: { empty: :empty, omitted: :omitted, nil: :nil },
@@ -205,7 +205,7 @@ module CustomCollection
205
205
  end
206
206
 
207
207
  key_value do
208
- root "items"
208
+ key "items"
209
209
 
210
210
  map_instances to: :items
211
211
  end
@@ -85,7 +85,7 @@ RSpec.describe "lutaml_default_register" do
85
85
  attribute :value, :string
86
86
 
87
87
  xml do
88
- root "test"
88
+ element "test"
89
89
  map_element "value", to: :value
90
90
  end
91
91
  end
@@ -105,7 +105,7 @@ RSpec.describe "lutaml_default_register" do
105
105
  attribute :name, :string
106
106
 
107
107
  xml do
108
- root "regular"
108
+ element "regular"
109
109
  end
110
110
  end
111
111
 
@@ -135,7 +135,7 @@ RSpec.describe "lutaml_default_register" do
135
135
  attribute :name, :string
136
136
 
137
137
  xml do
138
- root "test"
138
+ element "test"
139
139
  map_element "name", to: :name
140
140
  end
141
141
  end
@@ -160,7 +160,7 @@ RSpec.describe "lutaml_default_register" do
160
160
  attribute :name, :string
161
161
 
162
162
  xml do
163
- root "regular"
163
+ element "regular"
164
164
  end
165
165
  end
166
166
 
@@ -180,7 +180,7 @@ RSpec.describe "lutaml_default_register" do
180
180
  attribute :value, :string
181
181
 
182
182
  xml do
183
- root "child"
183
+ element "child"
184
184
  map_element "value", to: :value
185
185
  end
186
186
  end
@@ -195,7 +195,7 @@ RSpec.describe "lutaml_default_register" do
195
195
  attribute :child, child_klass
196
196
 
197
197
  xml do
198
- root "parent"
198
+ element "parent"
199
199
  map_element "child", to: :child
200
200
  end
201
201
  end
@@ -258,7 +258,7 @@ RSpec.describe "lutaml_default_register" do
258
258
  attribute :value, :string
259
259
 
260
260
  xml do
261
- root "math"
261
+ element "math"
262
262
  map_element "value", to: :value
263
263
  end
264
264
  end
@@ -267,7 +267,7 @@ RSpec.describe "lutaml_default_register" do
267
267
  attribute :value, :string
268
268
 
269
269
  xml do
270
- root "math"
270
+ element "math"
271
271
  map_element "value", to: :value
272
272
  end
273
273
  end
@@ -432,7 +432,7 @@ RSpec.describe "lutaml_default_register" do
432
432
  attribute :mmultiscripts_value, :mmultiscripts, collection: true
433
433
 
434
434
  xml do
435
- root "math"
435
+ element "math"
436
436
  map_element "mmultiscripts", to: :mmultiscripts_value
437
437
  end
438
438
  end
@@ -445,7 +445,7 @@ RSpec.describe "lutaml_default_register" do
445
445
  attribute :math, math_class
446
446
 
447
447
  xml do
448
- root "doc"
448
+ element "doc"
449
449
  map_element "math", to: :math
450
450
  end
451
451
  end
@@ -477,7 +477,7 @@ RSpec.describe "lutaml_default_register" do
477
477
  attribute :mi_value, :string
478
478
 
479
479
  xml do
480
- root "mmultiscripts"
480
+ element "mmultiscripts"
481
481
  map_element "mi", to: :mi_value
482
482
  end
483
483
  end
@@ -490,7 +490,7 @@ RSpec.describe "lutaml_default_register" do
490
490
  attribute :mmultiscripts_value, mmultiscripts_class, collection: true
491
491
 
492
492
  xml do
493
- root "math"
493
+ element "math"
494
494
  map_element "mmultiscripts", to: :mmultiscripts_value
495
495
  end
496
496
  end
@@ -504,7 +504,7 @@ RSpec.describe "lutaml_default_register" do
504
504
  attribute :math, math_class
505
505
 
506
506
  xml do
507
- root "doc"
507
+ element "doc"
508
508
  map_attribute "id", to: :id
509
509
  map_element "math", to: :math
510
510
  end
@@ -563,7 +563,7 @@ RSpec.describe "lutaml_default_register" do
563
563
  attribute :value, :string
564
564
 
565
565
  xml do
566
- root "mi"
566
+ element "mi"
567
567
  map_content to: :value
568
568
  end
569
569
  end
@@ -573,7 +573,7 @@ RSpec.describe "lutaml_default_register" do
573
573
  attribute :value, :string
574
574
 
575
575
  xml do
576
- root "mi"
576
+ element "mi"
577
577
  map_content to: :value
578
578
  end
579
579
  end
@@ -588,7 +588,7 @@ RSpec.describe "lutaml_default_register" do
588
588
  attribute :mi_value, standard_mi, collection: true
589
589
 
590
590
  xml do
591
- root "math"
591
+ element "math"
592
592
  map_element "mi", to: :mi_value
593
593
  end
594
594
  end
@@ -626,7 +626,7 @@ RSpec.describe "lutaml_default_register" do
626
626
  attribute :value, :string
627
627
 
628
628
  xml do
629
- root "mi"
629
+ element "mi"
630
630
  map_content to: :value
631
631
  end
632
632
  end
@@ -728,7 +728,7 @@ RSpec.describe "lutaml_default_register" do
728
728
  attribute :value, :string
729
729
 
730
730
  xml do
731
- root "inner"
731
+ element "inner"
732
732
  map_content to: :value
733
733
  end
734
734
  end
@@ -746,7 +746,7 @@ RSpec.describe "lutaml_default_register" do
746
746
  attribute :inner, :inner_element
747
747
 
748
748
  xml do
749
- root "child"
749
+ element "child"
750
750
  map_element "inner", to: :inner
751
751
  end
752
752
  end
@@ -756,7 +756,7 @@ RSpec.describe "lutaml_default_register" do
756
756
  attribute :child_elem, child_class
757
757
 
758
758
  xml do
759
- root "parent"
759
+ element "parent"
760
760
  map_element "child", to: :child_elem
761
761
  end
762
762
  end
@@ -774,7 +774,7 @@ RSpec.describe "lutaml_default_register" do
774
774
  attribute :content, :string
775
775
 
776
776
  xml do
777
- root "item"
777
+ element "item"
778
778
  map_content to: :content
779
779
  end
780
780
  end
@@ -790,7 +790,7 @@ RSpec.describe "lutaml_default_register" do
790
790
  attribute :items, :inner_element, collection: true
791
791
 
792
792
  xml do
793
- root "items"
793
+ element "items"
794
794
  map_element "item", to: :items
795
795
  end
796
796
  end
@@ -799,7 +799,7 @@ RSpec.describe "lutaml_default_register" do
799
799
  attribute :container, child_class
800
800
 
801
801
  xml do
802
- root "doc"
802
+ element "doc"
803
803
  map_element "items", to: :container
804
804
  end
805
805
  end
@@ -266,23 +266,16 @@ RSpec.describe Delegation do
266
266
  expect(xml_data).not_to include("<?xml")
267
267
  end
268
268
 
269
- it "provides XML declaration with default version" \
269
+ it "provides XML declaration with default version and encoding" \
270
270
  "if declaration: true option provided" do
271
271
  xml_data = delegation.to_xml(pretty: true, declaration: true)
272
- expect(xml_data).to include('<?xml version="1.0"?>')
272
+ expect(xml_data).to include('<?xml version="1.0" encoding="UTF-8"?>')
273
273
  end
274
274
 
275
275
  it "provides XML declaration with specified version" \
276
276
  "if declaration: '1.1' option provided" do
277
277
  xml_data = delegation.to_xml(pretty: true, declaration: "1.1")
278
- expect(xml_data).to include('<?xml version="1.1"?>')
279
- end
280
-
281
- it "provides XML declaration without encoding" \
282
- "if encoding option not provided" do
283
- xml_data = delegation.to_xml(pretty: true, declaration: true)
284
- expect(xml_data).to include('<?xml version="1.0"?>')
285
- expect(xml_data).not_to include("encoding=")
278
+ expect(xml_data).to include('<?xml version="1.1" encoding="UTF-8"?>')
286
279
  end
287
280
 
288
281
  it "provides XML declaration with UTF-8 encoding" \
@@ -7,7 +7,7 @@ module DerivedAttributeSerializationSpec
7
7
  attribute :computed_val, :string, method: :computed_value
8
8
 
9
9
  xml do
10
- root "parent"
10
+ element "parent"
11
11
  map_attribute "computed-val", to: :computed_val, render_default: true
12
12
  end
13
13
 
@@ -32,7 +32,7 @@ RSpec.describe "Dynamic attribute addition after register imports" do
32
32
  attribute :name, :string
33
33
 
34
34
  xml do
35
- root "BaseModel"
35
+ element "BaseModel"
36
36
  namespace DynAttrTestNamespace
37
37
  map_element "Name", to: :name
38
38
  end
@@ -44,7 +44,7 @@ RSpec.describe "Dynamic attribute addition after register imports" do
44
44
  attribute :code, :string
45
45
 
46
46
  xml do
47
- root "ExtensionModel"
47
+ element "ExtensionModel"
48
48
  namespace DynAttrTestNamespace
49
49
  map_element "Code", to: :code
50
50
  end
@@ -14,7 +14,7 @@ module EnumSpec
14
14
  attribute :char, :string
15
15
 
16
16
  xml do
17
- root "test"
17
+ element "test"
18
18
  map_attribute "align", to: :align
19
19
  map_attribute "char", to: :char
20
20
  end
@@ -213,7 +213,7 @@ module GroupSpec
213
213
  end
214
214
 
215
215
  RSpec.describe "Group" do
216
- context "when serializing and deserializing import model having no_root" do
216
+ context "when serializing and deserializing imported type-only models" do
217
217
  let(:xml) do
218
218
  # W3C Rule: Namespaces can be declared at point of use (local) or at root (hoisted).
219
219
  # Implementation prefers default format for cleaner output when creating new instances.
@@ -262,28 +262,28 @@ RSpec.describe "Group" do
262
262
  end
263
263
  end
264
264
 
265
- context "with no_root" do
265
+ context "with type-only model (no element declared)" do
266
266
  let(:mapper) { GroupSpec::CeramicCollection }
267
267
 
268
- it "raises error if root-less class used directly for parsing" do
268
+ it "raises error if type-only class used directly for parsing" do
269
269
  xml = <<~XML
270
270
  <type>Data</type>
271
271
  <name>Smith</name>
272
272
  XML
273
273
 
274
274
  expect { GroupSpec::Ceramic.from_xml(xml) }.to raise_error(
275
- Lutaml::Model::NoRootMappingError,
276
- "GroupSpec::Ceramic has `no_root`, it allowed only for reusable models",
275
+ Lutaml::Model::TypeOnlyMappingError,
276
+ /type-only model/,
277
277
  )
278
278
  end
279
279
 
280
- context "deserializing XML" do
280
+ context "serializing XML" do
281
281
  let(:ceramic) { GroupSpec::Ceramic.new(type: "Data", name: "Starc") }
282
282
 
283
- it "raises error for root_less class" do
283
+ it "raises error for type-only class" do
284
284
  expect { ceramic.to_xml }.to raise_error(
285
- Lutaml::Model::NoRootMappingError,
286
- "GroupSpec::Ceramic has `no_root`, it allowed only for reusable models",
285
+ Lutaml::Model::TypeOnlyMappingError,
286
+ /type-only model/,
287
287
  )
288
288
  end
289
289
  end
@@ -553,7 +553,7 @@ RSpec.describe "Group" do
553
553
  "Cannot import a model `GroupSpec::GroupWithRoot` with a root element")
554
554
  end
555
555
 
556
- it "raises error if namespace is defined with no_root" do
556
+ it "raises error if namespace is defined with deprecated no_root" do
557
557
  expect do
558
558
  Class.new(Lutaml::Model::Serializable) do
559
559
  xml do
@@ -561,8 +561,8 @@ RSpec.describe "Group" do
561
561
  namespace XmiNamespace
562
562
  end
563
563
  end
564
- end.to raise_error(Lutaml::Model::NoRootNamespaceError,
565
- "Cannot assign namespace to `no_root`")
564
+ end.to raise_error(Lutaml::Model::TypeOnlyNamespaceError,
565
+ /type-only model/)
566
566
  end
567
567
  end
568
568
 
@@ -10,7 +10,7 @@ module LazyCollectionTests
10
10
  attribute :name, :string
11
11
 
12
12
  xml do
13
- root "multi"
13
+ element "multi"
14
14
  map_element "name", to: :name
15
15
  map_element "item_a", to: :items_a
16
16
  map_element "item_b", to: :items_b
@@ -23,7 +23,7 @@ module LazyCollectionTests
23
23
  attribute :name, :string
24
24
 
25
25
  xml do
26
- root "tagged"
26
+ element "tagged"
27
27
  map_element "name", to: :name
28
28
  map_element "tag", to: :tags
29
29
  end
@@ -33,7 +33,7 @@ module LazyCollectionTests
33
33
  attribute :value, :string
34
34
 
35
35
  xml do
36
- root "child"
36
+ element "child"
37
37
  map_element "value", to: :value
38
38
  end
39
39
  end
@@ -47,7 +47,7 @@ module LazyCollectionTests
47
47
  attribute :name, :string
48
48
 
49
49
  xml do
50
- root "parent"
50
+ element "parent"
51
51
  map_element "name", to: :name
52
52
  map_element "child1", to: :col_1
53
53
  map_element "child2", to: :col_2
@@ -257,7 +257,7 @@ module MixedContentSpec
257
257
  attribute :mathvariant, :string
258
258
 
259
259
  xml do
260
- root "mi"
260
+ element "mi"
261
261
  mixed_content
262
262
  map_content to: :value
263
263
  map_attribute "mathvariant", to: :mathvariant
@@ -269,7 +269,7 @@ module MixedContentSpec
269
269
  attribute :bold, :string
270
270
 
271
271
  xml do
272
- root "p"
272
+ element "p"
273
273
  mixed_content
274
274
  map_content to: :content
275
275
  map_element "b", to: :bold
@@ -93,7 +93,7 @@ RSpec.describe Lutaml::Model::ModelTreeImporter do
93
93
  attribute :value, :integer
94
94
 
95
95
  xml do
96
- root "Simple"
96
+ element "Simple"
97
97
  map_element "name", to: :name
98
98
  map_element "value", to: :value
99
99
  end
@@ -322,7 +322,7 @@ RSpec.describe "Context Propagation for Mixed Schema Types" do
322
322
  attribute :custom_field, :custom_type_for_context
323
323
 
324
324
  xml do
325
- root "Child"
325
+ element "Child"
326
326
  map_element "CustomField", to: :custom_field
327
327
  end
328
328
  end
@@ -341,7 +341,7 @@ RSpec.describe "Context Propagation for Mixed Schema Types" do
341
341
  attribute :child, child_klass
342
342
 
343
343
  xml do
344
- root "Parent"
344
+ element "Parent"
345
345
  map_element "Child", to: :child
346
346
  end
347
347
  end
@@ -369,7 +369,7 @@ RSpec.describe "Context Propagation for Mixed Schema Types" do
369
369
  attribute :children, child_klass, collection: true
370
370
 
371
371
  xml do
372
- root "Parent"
372
+ element "Parent"
373
373
  map_element "Child", to: :children
374
374
  end
375
375
  end
@@ -0,0 +1,117 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe "Opal compatibility", if: RUBY_ENGINE == "opal" do
6
+ it "includes Serialize in a class" do
7
+ klass = Class.new { include Lutaml::Model::Serialize }
8
+ expect(klass.include?(Lutaml::Model::Serialize)).to be true
9
+ end
10
+
11
+ it "defines attributes and serializes to hash" do
12
+ person = Class.new do
13
+ include Lutaml::Model::Serialize
14
+
15
+ attribute :name, :string
16
+ attribute :age, :integer
17
+ end
18
+
19
+ instance = person.new(name: "Alice", age: 30)
20
+ expect(instance.to_hash).to eq({ "name" => "Alice", "age" => 30 })
21
+ end
22
+
23
+ it "round-trips JSON serialization" do
24
+ person = Class.new do
25
+ include Lutaml::Model::Serialize
26
+
27
+ attribute :name, :string
28
+ attribute :age, :integer
29
+ end
30
+
31
+ instance = person.from_json('{"name":"Bob","age":25}')
32
+ expect(instance.name).to eq("Bob")
33
+ expect(instance.age).to eq(25)
34
+ end
35
+
36
+ it "handles collections" do
37
+ team = Class.new do
38
+ include Lutaml::Model::Serialize
39
+
40
+ attribute :members, :string, collection: true
41
+ end
42
+
43
+ instance = team.new(members: %w[Alice Bob Carol])
44
+ expect(instance.members).to eq(%w[Alice Bob Carol])
45
+ end
46
+
47
+ it "handles defaults" do
48
+ widget = Class.new do
49
+ include Lutaml::Model::Serialize
50
+
51
+ attribute :name, :string
52
+ attribute :active, :boolean, default: -> { true }
53
+ end
54
+
55
+ instance = widget.new(name: "test")
56
+ expect(instance.active).to be true
57
+ end
58
+
59
+ it "handles type coercion" do
60
+ record = Class.new do
61
+ include Lutaml::Model::Serialize
62
+
63
+ attribute :count, :integer
64
+ attribute :ratio, :float
65
+ attribute :flag, :boolean
66
+ end
67
+
68
+ instance = record.new(count: "42", ratio: "3.14", flag: "true")
69
+ expect(instance.count).to eq(42)
70
+ expect(instance.ratio).to eq(3.14)
71
+ expect(instance.flag).to be true
72
+ end
73
+
74
+ it "handles nested models" do
75
+ address = Class.new do
76
+ include Lutaml::Model::Serialize
77
+
78
+ attribute :city, :string
79
+ attribute :zip, :string
80
+ end
81
+
82
+ person = Class.new do
83
+ include Lutaml::Model::Serialize
84
+
85
+ attribute :name, :string
86
+ attribute :address, address
87
+ end
88
+
89
+ instance = person.new(name: "Alice",
90
+ address: address.new(
91
+ city: "NYC", zip: "10001",
92
+ ))
93
+ expect(instance.address.city).to eq("NYC")
94
+ end
95
+
96
+ it "handles YAML serialization" do
97
+ config = Class.new do
98
+ include Lutaml::Model::Serialize
99
+
100
+ attribute :host, :string
101
+ attribute :port, :integer
102
+ end
103
+
104
+ instance = config.from_yaml("host: localhost\nport: 8080\n")
105
+ expect(instance.host).to eq("localhost")
106
+ expect(instance.port).to eq(8080)
107
+ end
108
+
109
+ it "RuntimeCompatibility detects Opal" do
110
+ expect(Lutaml::Model::RuntimeCompatibility.opal?).to be true
111
+ end
112
+
113
+ it "AdapterResolver auto-detects REXML" do
114
+ adapter = Lutaml::Model::AdapterResolver.detect_xml_adapter
115
+ expect(adapter).to eq(:rexml)
116
+ end
117
+ end
@@ -32,7 +32,7 @@ RSpec.describe "Processing Instructions" do
32
32
  attribute :pi_settings, :hash
33
33
 
34
34
  xml do
35
- root "rfc"
35
+ element "rfc"
36
36
  map_element "title", to: :title
37
37
  map_processing_instruction "rfc", to: :pi_settings
38
38
  end
@@ -57,7 +57,7 @@ RSpec.describe "Processing Instructions" do
57
57
  attribute :pi_settings, :hash
58
58
 
59
59
  xml do
60
- root "rfc"
60
+ element "rfc"
61
61
  map_element "title", to: :title
62
62
  map_processing_instruction "rfc", to: :pi_settings
63
63
  end
@@ -76,7 +76,7 @@ RSpec.describe "Processing Instructions" do
76
76
  attribute :pi_settings, :hash
77
77
 
78
78
  xml do
79
- root "rfc"
79
+ element "rfc"
80
80
  map_element "title", to: :title
81
81
  map_processing_instruction "rfc", to: :pi_settings
82
82
  end
@@ -96,7 +96,7 @@ RSpec.describe "Processing Instructions" do
96
96
  attribute :xml_pis, :hash
97
97
 
98
98
  xml do
99
- root "doc"
99
+ element "doc"
100
100
  map_element "title", to: :title
101
101
  map_processing_instruction "rfc", to: :rfc_pis
102
102
  map_processing_instruction "xml-stylesheet", to: :xml_pis
@@ -120,7 +120,7 @@ RSpec.describe "Processing Instructions" do
120
120
  attribute :pi_settings, :hash
121
121
 
122
122
  xml do
123
- root "rfc"
123
+ element "rfc"
124
124
  map_element "title", to: :title
125
125
  map_processing_instruction "rfc", to: :pi_settings
126
126
  end
@@ -143,7 +143,7 @@ RSpec.describe "Processing Instructions" do
143
143
  attribute :title, :string
144
144
 
145
145
  xml do
146
- root "doc"
146
+ element "doc"
147
147
  map_element "title", to: :title
148
148
  end
149
149
  end
@@ -238,7 +238,7 @@ RSpec.describe "Processing Instructions" do
238
238
  attribute :pi_settings, :hash
239
239
 
240
240
  xml do
241
- root "rfc"
241
+ element "rfc"
242
242
  map_element "title", to: :title
243
243
  map_processing_instruction "rfc", to: :pi_settings
244
244
  end
@@ -266,7 +266,7 @@ RSpec.describe "Processing Instructions" do
266
266
  attribute :pi_settings, :hash
267
267
 
268
268
  xml do
269
- root "rfc"
269
+ element "rfc"
270
270
  map_element "title", to: :title
271
271
  map_processing_instruction "rfc", to: :pi_settings
272
272
  end
@@ -284,7 +284,7 @@ RSpec.describe "Processing Instructions" do
284
284
  attribute :stylesheet_pis, :hash
285
285
 
286
286
  xml do
287
- root "doc"
287
+ element "doc"
288
288
  map_element "title", to: :title
289
289
  map_processing_instruction "rfc", to: :rfc_pis
290
290
  map_processing_instruction "xml-stylesheet", to: :stylesheet_pis
@@ -312,7 +312,7 @@ RSpec.describe "Processing Instructions" do
312
312
  attribute :db_pis, :hash
313
313
 
314
314
  xml do
315
- root "book"
315
+ element "book"
316
316
  map_element "title", to: :title
317
317
  map_processing_instruction "db", to: :db_pis
318
318
  end
@@ -333,7 +333,7 @@ RSpec.describe "Processing Instructions" do
333
333
  attribute :rfc_pis, :string, collection: true
334
334
 
335
335
  xml do
336
- root "rfc"
336
+ element "rfc"
337
337
  map_element "title", to: :title
338
338
  map_processing_instruction "rfc", to: :rfc_pis
339
339
  end
@@ -13,7 +13,7 @@ RSpec.describe "Register-specific attribute methods" do
13
13
  attribute :name, :string
14
14
 
15
15
  xml do
16
- root "Base"
16
+ element "Base"
17
17
  map_element "Name", to: :name
18
18
  end
19
19
  end
@@ -25,7 +25,7 @@ RSpec.describe "Register-specific attribute methods" do
25
25
  attribute :priority, :integer
26
26
 
27
27
  xml do
28
- root "Extension"
28
+ element "Extension"
29
29
  map_element "Version", to: :version
30
30
  map_element "Priority", to: :priority
31
31
  end
@@ -80,7 +80,7 @@ module RenderEmptySpec
80
80
  attribute :page, :string
81
81
 
82
82
  xml do
83
- root "doc"
83
+ element "doc"
84
84
  map_attribute "code", to: :code
85
85
  map_attribute "page", to: :page,
86
86
  value_map: { to: { empty: :empty } }