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
@@ -126,7 +126,7 @@ class Ceramic < Lutaml::Model::Serializable
126
126
 
127
127
  # Mapping-level transformation in XML format
128
128
  xml do
129
- root "Ceramic"
129
+ element "Ceramic"
130
130
  map_attribute "glaze-type", to: :glaze_type, transform: {
131
131
  export: ->(value) { "Traditional #{value}" },
132
132
  import: ->(value) { value.gsub("Traditional ", "") }
@@ -234,7 +234,7 @@ class Ceramic < Lutaml::Model::Serializable
234
234
 
235
235
  # Mapping-level transformation in XML format
236
236
  xml do
237
- root "Ceramic"
237
+ element "Ceramic"
238
238
  map_attribute "glaze-type", to: :glaze_type, transform: {
239
239
  export: ->(value) { "Traditional #{value}" },
240
240
  import: ->(value) { value.gsub("Traditional ", "") }
@@ -454,7 +454,7 @@ class CombinedTransformModel < Lutaml::Model::Serializable
454
454
  end
455
455
 
456
456
  xml do
457
- root "CombinedTransformModel"
457
+ element "CombinedTransformModel"
458
458
  map_element "title", to: :title, transform: SuffixTransformer
459
459
  end
460
460
  end
@@ -662,7 +662,7 @@ class Glaze < Lutaml::Model::Serializable
662
662
  attribute :firing_time, :integer, default: -> { 60 }
663
663
 
664
664
  xml do
665
- root "glaze"
665
+ element "glaze"
666
666
  map_element 'color', to: :color
667
667
  map_element 'opacity', to: :opacity, render_default: true
668
668
  map_attribute 'temperature', to: :temperature
@@ -31,7 +31,7 @@ class JapaneseCeramic < Lutaml::Model::Serializable
31
31
  attribute :description, :string
32
32
 
33
33
  xml do
34
- root 'JapaneseCeramic'
34
+ element "JapaneseCeramic"
35
35
  map_attribute 'glazeType', to: :glaze_type
36
36
  map_element 'description', to: :description
37
37
  end
@@ -34,7 +34,7 @@ class Tag < Lutaml::Model::Serializable
34
34
  attribute :text, :string
35
35
 
36
36
  xml do
37
- root "Tag"
37
+ element "Tag"
38
38
 
39
39
  map_content to: :text
40
40
  end
@@ -48,7 +48,7 @@ class Tags < Lutaml::Model::Serializable
48
48
  attribute :tag, Tag, collection: true
49
49
 
50
50
  xml do
51
- root "Tags"
51
+ element "Tags"
52
52
 
53
53
  map_element "Tag", to: :tag
54
54
  end
@@ -62,7 +62,7 @@ class Post < Lutaml::Model::Serializable
62
62
  attribute :tags, Tags, collection: true
63
63
 
64
64
  xml do
65
- root "Post"
65
+ element "Post"
66
66
  map_element "Tags", to: :tags
67
67
  end
68
68
 
@@ -121,7 +121,7 @@ class Kiln < Lutaml::Model::Serializable
121
121
  attribute :temperature, :integer
122
122
 
123
123
  xml do
124
- root 'kiln'
124
+ element "kiln"
125
125
  map_element 'brand', to: :brand
126
126
  map_element 'capacity', to: :capacity
127
127
  map_element 'temperature', to: :temperature
@@ -74,7 +74,7 @@ class Example < Lutaml::Model::Serializable
74
74
  attribute :name, :string
75
75
 
76
76
  xml do
77
- root 'example'
77
+ element "example"
78
78
  map_element 'name', to: :name
79
79
  end
80
80
  end
@@ -116,7 +116,7 @@ class Example < Lutaml::Model::Serializable
116
116
  attribute :value, :integer
117
117
 
118
118
  xml do
119
- root 'example'
119
+ element "example"
120
120
  map_attribute 'value', to: :value
121
121
  end
122
122
  end
@@ -158,7 +158,7 @@ class Example < Lutaml::Model::Serializable
158
158
  attribute :description, :string
159
159
 
160
160
  xml do
161
- root 'example'
161
+ element "example"
162
162
  map_content to: :description
163
163
  end
164
164
  end
@@ -192,7 +192,7 @@ class Ceramic < Lutaml::Model::Serializable
192
192
  attribute :temperature, :integer
193
193
 
194
194
  xml do
195
- root 'ceramic'
195
+ element "ceramic"
196
196
  map_element 'name', to: :name
197
197
  map_attribute 'temperature', to: :temperature
198
198
  map_content to: :description
@@ -576,7 +576,7 @@ end
576
576
  ```ruby
577
577
  class PurchaseOrder < Lutaml::Model::Serializable
578
578
  xml do
579
- root "purchaseOrder" # Root element name
579
+ element "purchaseOrder" # Root element name
580
580
  namespace PoNamespace # Model namespace
581
581
 
582
582
  map_element "shipTo", to: :ship_to # Map element
@@ -654,7 +654,7 @@ class Book < Lutaml::Model::Serializable
654
654
  attribute :author, Person
655
655
 
656
656
  xml do
657
- root "Book"
657
+ element "Book"
658
658
  namespace BookNamespace
659
659
  map_element "title", to: :title
660
660
  map_element "author", to: :author
@@ -979,7 +979,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
979
979
  attribute :comment, :string
980
980
 
981
981
  xml do
982
- root "purchaseOrder"
982
+ element "purchaseOrder"
983
983
  namespace PoNamespace
984
984
  map_element "comment", to: :comment
985
985
  end
@@ -1062,7 +1062,7 @@ class Document < Lutaml::Model::Serializable
1062
1062
  attribute :title, DcTitleType
1063
1063
 
1064
1064
  xml do
1065
- root "document"
1065
+ element "document"
1066
1066
  map_element "title", to: :title
1067
1067
  end
1068
1068
  end
@@ -152,7 +152,7 @@ class Contact < Lutaml::Model::Serializable
152
152
  end
153
153
 
154
154
  xml do
155
- root "contact"
155
+ element "contact"
156
156
  map_element "email", to: :email
157
157
  map_element "phone", to: :phone
158
158
  end
@@ -39,7 +39,7 @@ class Studio < Lutaml::Model::Serializable
39
39
  attribute :potters, :string, collection: true
40
40
 
41
41
  xml do
42
- root 'studio'
42
+ element "studio"
43
43
  map_element 'name', to: :name
44
44
  map_element 'potter', to: :potters
45
45
  end
@@ -142,7 +142,7 @@ class PotterCollection < Lutaml::Model::Collection
142
142
  instances :potters, Potter
143
143
 
144
144
  json do
145
- root "potters"
145
+ key "potters"
146
146
  map_instances to: :potters
147
147
  end
148
148
  end
@@ -70,7 +70,7 @@ class Ceramic < Lutaml::Model::Serializable
70
70
  attribute :glaze, :string
71
71
 
72
72
  xml do
73
- root 'Ceramic'
73
+ element "Ceramic"
74
74
  namespace CeramicNamespace
75
75
 
76
76
  map_element 'Type', to: :type
@@ -46,7 +46,7 @@ class UsAddress < Lutaml::Model::Serializable
46
46
  attribute :zip, :decimal
47
47
 
48
48
  xml do
49
- root "USAddress"
49
+ element "USAddress"
50
50
  map_element "name", to: :name
51
51
  map_element "street", to: :street
52
52
  map_element "city", to: :city
@@ -81,7 +81,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
81
81
  attribute :comment, :string
82
82
 
83
83
  xml do
84
- root "purchaseOrder"
84
+ element "purchaseOrder"
85
85
  map_element "shipTo", to: :ship_to
86
86
  map_element "billTo", to: :bill_to
87
87
  map_element "comment", to: :comment
@@ -123,7 +123,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
123
123
  attribute :ship_to, UsAddress
124
124
 
125
125
  xml do
126
- root "purchaseOrder"
126
+ element "purchaseOrder"
127
127
  map_attribute "orderDate", to: :order_date
128
128
  map_element "shipTo", to: :ship_to
129
129
  end
@@ -157,7 +157,7 @@ class Item < Lutaml::Model::Serializable
157
157
  attribute :us_price, :decimal
158
158
 
159
159
  xml do
160
- root "Item"
160
+ element "Item"
161
161
  map_element "productName", to: :product_name
162
162
  map_element "quantity", to: :quantity
163
163
  map_element "USPrice", to: :us_price
@@ -168,7 +168,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
168
168
  attribute :items, Item, collection: true
169
169
 
170
170
  xml do
171
- root "purchaseOrder"
171
+ element "purchaseOrder"
172
172
  map_element "items", to: :items
173
173
  end
174
174
  end
@@ -239,7 +239,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
239
239
  attribute :bill_to, UsAddress
240
240
 
241
241
  xml do
242
- root "purchaseOrder"
242
+ element "purchaseOrder"
243
243
  namespace PoNamespace
244
244
 
245
245
  map_element "shipTo", to: :ship_to
@@ -288,7 +288,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
288
288
  attribute :ship_to, UsAddress
289
289
 
290
290
  xml do
291
- root "purchaseOrder"
291
+ element "purchaseOrder"
292
292
  namespace PoNamespace
293
293
 
294
294
  map_element "shipTo", to: :ship_to
@@ -350,7 +350,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
350
350
  attribute :order_date, :string
351
351
 
352
352
  xml do
353
- root "purchaseOrder"
353
+ element "purchaseOrder"
354
354
  namespace PoNamespace
355
355
 
356
356
  map_attribute "orderDate", to: :order_date
@@ -418,7 +418,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
418
418
  attribute :comment, :string # This one will be unqualified
419
419
 
420
420
  xml do
421
- root "purchaseOrder"
421
+ element "purchaseOrder"
422
422
  namespace PoNamespace
423
423
 
424
424
  map_element "shipTo", to: :ship_to
@@ -489,7 +489,7 @@ class Document < Lutaml::Model::Serializable
489
489
  attribute :title, DcTitleType # Automatically uses DcNamespace
490
490
 
491
491
  xml do
492
- root "document"
492
+ element "document"
493
493
  map_element "title", to: :title
494
494
  end
495
495
  end
@@ -542,7 +542,7 @@ class Metadata < Lutaml::Model::Serializable
542
542
  attribute :created, DctermsCreatedType
543
543
 
544
544
  xml do
545
- root "metadata"
545
+ element "metadata"
546
546
  map_element "title", to: :title
547
547
  map_element "created", to: :created
548
548
  end
@@ -586,7 +586,7 @@ class Document < Lutaml::Model::Serializable
586
586
  attribute :title, DcTitleType
587
587
 
588
588
  xml do
589
- root "document"
589
+ element "document"
590
590
  namespace ModelNamespace # Model namespace
591
591
  map_element "title", to: :title # Uses Type namespace (DcNamespace)
592
592
  end
@@ -620,7 +620,7 @@ class Document < Lutaml::Model::Serializable
620
620
  attribute :title, DcTitleType
621
621
 
622
622
  xml do
623
- root "document"
623
+ element "document"
624
624
  map_element "title", to: :title, namespace: OverrideNamespace
625
625
  end
626
626
  end
@@ -659,7 +659,7 @@ class Document < Lutaml::Model::Serializable
659
659
  attribute :schema_type, XsiTypeType
660
660
 
661
661
  xml do
662
- root "document"
662
+ element "document"
663
663
  map_attribute "name", to: :name
664
664
  map_attribute "type", to: :schema_type
665
665
  end
@@ -701,7 +701,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
701
701
  attribute :ship_to, UsAddress
702
702
 
703
703
  xml do
704
- root "purchaseOrder"
704
+ element "purchaseOrder"
705
705
  namespace PoNamespace
706
706
  map_element "shipTo", to: :ship_to
707
707
  end
@@ -749,7 +749,7 @@ The `namespace_scope` directive consolidates multiple namespace declarations at
749
749
  ----
750
750
  class Document < Lutaml::Model::Serializable
751
751
  xml do
752
- root "document"
752
+ element "document"
753
753
  namespace RootNamespace
754
754
 
755
755
  # Hoist multiple namespaces to root
@@ -794,7 +794,7 @@ class Vcard < Lutaml::Model::Serializable
794
794
  attribute :title, DcTitleType
795
795
 
796
796
  xml do
797
- root "vCard"
797
+ element "vCard"
798
798
  namespace VcardNamespace
799
799
 
800
800
  # Hoist DcNamespace to root
@@ -882,7 +882,7 @@ class Address < Lutaml::Model::Serializable
882
882
  attribute :city, :string
883
883
 
884
884
  xml do
885
- root "Address"
885
+ element "Address"
886
886
  map_element "street", to: :street
887
887
  map_element "city", to: :city
888
888
  end
@@ -893,7 +893,7 @@ class Person < Lutaml::Model::Serializable
893
893
  attribute :address, Address
894
894
 
895
895
  xml do
896
- root "Person"
896
+ element "Person"
897
897
  map_element "name", to: :name
898
898
  map_element "address", to: :address
899
899
  end
@@ -934,7 +934,7 @@ class Person < Lutaml::Model::Serializable
934
934
  attribute :work_address, AddressType
935
935
 
936
936
  xml do
937
- root "Person"
937
+ element "Person"
938
938
  map_element "homeAddress", to: :home_address
939
939
  map_element "workAddress", to: :work_address
940
940
  end
@@ -975,7 +975,7 @@ class Item < Lutaml::Model::Serializable
975
975
  attribute :price, Price
976
976
 
977
977
  xml do
978
- root "Item"
978
+ element "Item"
979
979
  map_element "name", to: :name
980
980
  map_attribute "price", to: :price
981
981
  end
@@ -1017,7 +1017,7 @@ class Product < Lutaml::Model::Serializable
1017
1017
  attribute :release_date, :date
1018
1018
 
1019
1019
  xml do
1020
- root "Product"
1020
+ element "Product"
1021
1021
  map_element "name", to: :name
1022
1022
  map_element "price", to: :price
1023
1023
  map_element "quantity", to: :quantity
@@ -1055,7 +1055,7 @@ class Item < Lutaml::Model::Serializable
1055
1055
  attribute :price, UsPriceType
1056
1056
 
1057
1057
  xml do
1058
- root "Item"
1058
+ element "Item"
1059
1059
  map_element "USPrice", to: :price
1060
1060
  end
1061
1061
  end
@@ -1106,7 +1106,7 @@ class Address < Lutaml::Model::Serializable
1106
1106
  attribute :city, :string
1107
1107
 
1108
1108
  xml do
1109
- root "Address"
1109
+ element "Address"
1110
1110
  map_element "name", to: :name
1111
1111
  map_element "street", to: :street
1112
1112
  map_element "city", to: :city
@@ -1118,7 +1118,7 @@ class InternationalAddress < Address
1118
1118
  attribute :country, :string
1119
1119
 
1120
1120
  xml do
1121
- root "InternationalAddress"
1121
+ element "InternationalAddress"
1122
1122
  map_element *Address.mappings # Inherit mappings
1123
1123
  map_element "country", to: :country
1124
1124
  end
@@ -1140,7 +1140,7 @@ class Shipment < Lutaml::Model::Serializable
1140
1140
  attribute :address, Address
1141
1141
 
1142
1142
  xml do
1143
- root "Shipment"
1143
+ element "Shipment"
1144
1144
  namespace_scope [XsiNamespace]
1145
1145
  map_element "address", to: :address
1146
1146
  end
@@ -1231,7 +1231,7 @@ class UsAddress < Lutaml::Model::Serializable
1231
1231
  attribute :zip, :decimal
1232
1232
 
1233
1233
  xml do
1234
- root "USAddress"
1234
+ element "USAddress"
1235
1235
  map_element "name", to: :name
1236
1236
  map_element "street", to: :street
1237
1237
  map_element "city", to: :city
@@ -1247,7 +1247,7 @@ class Item < Lutaml::Model::Serializable
1247
1247
  attribute :comment, :string
1248
1248
 
1249
1249
  xml do
1250
- root "Item"
1250
+ element "Item"
1251
1251
  map_element "productName", to: :product_name
1252
1252
  map_element "quantity", to: :quantity
1253
1253
  map_element "USPrice", to: :us_price
@@ -1264,7 +1264,7 @@ class PurchaseOrder < Lutaml::Model::Serializable
1264
1264
  attribute :created, DctermsCreatedType
1265
1265
 
1266
1266
  xml do
1267
- root "purchaseOrder"
1267
+ element "purchaseOrder"
1268
1268
  namespace PoNamespace
1269
1269
 
1270
1270
  namespace_scope [
@@ -69,7 +69,7 @@ class TermiumExtract < Lutaml::Model::Serializable
69
69
  attribute :extract_language, ExtractLanguage, collection: true
70
70
 
71
71
  xml do
72
- root "termium_extract"
72
+ element "termium_extract"
73
73
  namespace "http://termium.tpsgc-pwgsc.gc.ca/schemas/2012/06/Termium", "ns2"
74
74
 
75
75
  map_attribute "language", to: :language
data/docs/index.adoc CHANGED
@@ -19,6 +19,7 @@ Lutaml::Model is a Ruby library for creating information models with attributes
19
19
  * **Multi-format serialization** - XML, JSON, YAML, TOML, JSON-LD, Turtle, Hash, YAML Stream
20
20
  * **XML namespace support** - Full W3C namespace implementation
21
21
  * **Linked Data support** - RDF namespaces, JSON-LD, and Turtle serialization
22
+ * **Opal support** - Run in the browser via Opal (Ruby to JavaScript) with REXML adapter
22
23
  * **Validation** - Built-in validation with custom rules
23
24
  * **Schema generation** - Generate XSD, JSON Schema, YAML Schema
24
25
  * **Polymorphism** - Handle multiple types elegantly
@@ -55,7 +56,7 @@ class Person < Lutaml::Model::Serializable
55
56
  attribute :age, :integer
56
57
 
57
58
  xml do
58
- root "person"
59
+ element "person"
59
60
  map_element "name", to: :name
60
61
  map_element "age", to: :age
61
62
  end
@@ -110,10 +110,10 @@ IMPORTANT: `namespace_scope` grants **ELIGIBILITY** to hoist namespaces to the r
110
110
  ----
111
111
  xml do
112
112
  namespace RootNamespace
113
-
113
+
114
114
  # Simple list (all use :auto mode)
115
115
  namespace_scope [Namespace1, Namespace2, Namespace3]
116
-
116
+
117
117
  # Per-namespace control with hash format
118
118
  namespace_scope [
119
119
  { namespace: Namespace1, declare: :always },
@@ -169,7 +169,7 @@ class Vcard < Lutaml::Model::Serializable
169
169
  attribute :email, :string
170
170
 
171
171
  xml do
172
- root "vCard"
172
+ element "vCard"
173
173
  namespace VcardNamespace
174
174
 
175
175
  map_element "version", to: :version
@@ -244,7 +244,7 @@ class Contact < Lutaml::Model::Serializable
244
244
  attribute :note, DcTitleType
245
245
 
246
246
  xml do
247
- root "contact"
247
+ element "contact"
248
248
 
249
249
  map_element "title", to: :title
250
250
  map_element "note", to: :note
@@ -255,7 +255,7 @@ class Vcard < Lutaml::Model::Serializable
255
255
  attribute :contact, Contact
256
256
 
257
257
  xml do
258
- root "vCard"
258
+ element "vCard"
259
259
  namespace VcardNamespace
260
260
 
261
261
  map_element "contact", to: :contact
@@ -300,7 +300,7 @@ class Vcard < Lutaml::Model::Serializable
300
300
  attribute :contact, Contact
301
301
 
302
302
  xml do
303
- root "vCard"
303
+ element "vCard"
304
304
  namespace VcardNamespace
305
305
 
306
306
  # Hoist DcNamespace to root
@@ -395,7 +395,7 @@ class Metadata < Lutaml::Model::Serializable
395
395
  attribute :format, XsiTypeType
396
396
 
397
397
  xml do
398
- root "metadata"
398
+ element "metadata"
399
399
 
400
400
  map_element "title", to: :title
401
401
  map_element "creator", to: :creator
@@ -411,7 +411,7 @@ class Vcard < Lutaml::Model::Serializable
411
411
  attribute :metadata, Metadata
412
412
 
413
413
  xml do
414
- root "vCard"
414
+ element "vCard"
415
415
  namespace VcardNamespace
416
416
 
417
417
  # Consolidate all namespaces at root
@@ -483,7 +483,7 @@ class Vcard < Lutaml::Model::Serializable
483
483
  # No DcTitleType attributes used
484
484
 
485
485
  xml do
486
- root "vCard"
486
+ element "vCard"
487
487
  namespace VcardNamespace
488
488
 
489
489
  # Try to hoist unused DcNamespace
@@ -630,7 +630,7 @@ class Parent < Lutaml::Model::Serializable
630
630
  attribute :child_value, :string
631
631
 
632
632
  xml do
633
- root "parent"
633
+ element "parent"
634
634
  namespace ParentNamespace
635
635
 
636
636
  map_element "child", to: :child_value
@@ -826,7 +826,7 @@ class Document < Lutaml::Model::Serializable
826
826
  attribute :title, DcTitleType # Automatically uses DcNamespace
827
827
 
828
828
  xml do
829
- root "document"
829
+ element "document"
830
830
  namespace DocumentNamespace
831
831
 
832
832
  map_element "title", to: :title # Becomes <dc:title>
@@ -845,7 +845,7 @@ Simplest case—all elements in one namespace:
845
845
  ----
846
846
  class Document < Lutaml::Model::Serializable
847
847
  xml do
848
- root "document"
848
+ element "document"
849
849
  namespace DocumentNamespace
850
850
  # No namespace_scope needed
851
851
  end
@@ -863,7 +863,7 @@ class Document < Lutaml::Model::Serializable
863
863
  attribute :created, DctermsCreatedType # DctermsNamespace
864
864
 
865
865
  xml do
866
- root "document"
866
+ element "document"
867
867
  namespace DocumentNamespace
868
868
  # No namespace_scope - Type namespaces hoist locally
869
869
  end
@@ -881,7 +881,7 @@ class Document < Lutaml::Model::Serializable
881
881
  attribute :created, DctermsCreatedType
882
882
 
883
883
  xml do
884
- root "document"
884
+ element "document"
885
885
  namespace DocumentNamespace
886
886
 
887
887
  # Hoist all Type namespaces to root
@@ -8,10 +8,8 @@ module Lutaml
8
8
  super(:hash)
9
9
  end
10
10
 
11
- def deep_dup
12
- self.class.new.tap do |new_mapping|
13
- new_mapping.mappings = duplicate_mappings
14
- end
11
+ def dup_instance
12
+ self.class.new
15
13
  end
16
14
  end
17
15
  end
@@ -8,10 +8,8 @@ module Lutaml
8
8
  super(:json)
9
9
  end
10
10
 
11
- def deep_dup
12
- self.class.new.tap do |new_mapping|
13
- new_mapping.mappings = duplicate_mappings
14
- end
11
+ def dup_instance
12
+ self.class.new
15
13
  end
16
14
  end
17
15
  end
@@ -8,10 +8,8 @@ module Lutaml
8
8
  super(:jsonl)
9
9
  end
10
10
 
11
- def deep_dup
12
- self.class.new.tap do |new_mapping|
13
- new_mapping.mappings = duplicate_mappings
14
- end
11
+ def dup_instance
12
+ self.class.new
15
13
  end
16
14
  end
17
15
  end
@@ -7,10 +7,8 @@ module Lutaml
7
7
  super(:hash)
8
8
  end
9
9
 
10
- def deep_dup
11
- self.class.new.tap do |new_mapping|
12
- new_mapping.mappings = duplicate_mappings
13
- end
10
+ def dup_instance
11
+ self.class.new
14
12
  end
15
13
  end
16
14
  end
@@ -12,10 +12,8 @@ module Lutaml
12
12
  super(:json)
13
13
  end
14
14
 
15
- def deep_dup
16
- self.class.new.tap do |new_mapping|
17
- new_mapping.mappings = duplicate_mappings
18
- end
15
+ def dup_instance
16
+ self.class.new
19
17
  end
20
18
  end
21
19
  end
@@ -7,10 +7,8 @@ module Lutaml
7
7
  super(:jsonl)
8
8
  end
9
9
 
10
- def deep_dup
11
- self.class.new.tap do |new_mapping|
12
- new_mapping.mappings = duplicate_mappings
13
- end
10
+ def dup_instance
11
+ self.class.new
14
12
  end
15
13
  end
16
14
  end