lutaml-model 0.8.201 → 0.8.203

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 (153) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/dependent-tests.yml +59 -2
  4. data/.github/workflows/downstream-performance.yml +1 -22
  5. data/.github/workflows/performance.yml +1 -33
  6. data/.github/workflows/rake.yml +2 -6
  7. data/.rubocop.yml +0 -10
  8. data/.rubocop_todo.yml +0 -4
  9. data/Gemfile +0 -23
  10. data/README.adoc +25 -86
  11. data/Rakefile +2 -167
  12. data/docs/_guides/advanced-mapping.adoc +6 -6
  13. data/docs/_guides/character-encoding.adoc +0 -3
  14. data/docs/_guides/gem-integration.adoc +1 -1
  15. data/docs/_guides/index.adoc +0 -4
  16. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  17. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  18. data/docs/_guides/xml-namespaces.adoc +2 -3
  19. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  20. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  21. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  22. data/docs/_pages/comparison-with-shale.adoc +1 -1
  23. data/docs/_pages/configuration.adoc +6 -40
  24. data/docs/_pages/index.adoc +0 -1
  25. data/docs/_pages/serialization_adapters.adoc +4 -16
  26. data/docs/_references/architecture.adoc +1 -1
  27. data/docs/_references/lutaml-namespace-planning.md +1 -1
  28. data/docs/_references/plan-schema-spec.adoc +45 -18
  29. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  30. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  31. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  32. data/docs/architecture.md +7 -11
  33. data/docs/conversion_caching.adoc +1 -1
  34. data/docs/index.adoc +0 -1
  35. data/docs/key_value_data_model.adoc +1 -1
  36. data/docs/namespace-management.adoc +4 -10
  37. data/lib/lutaml/json/format.rb +0 -1
  38. data/lib/lutaml/json/generator_options.rb +0 -1
  39. data/lib/lutaml/key_value/transform.rb +149 -37
  40. data/lib/lutaml/lml/document_builder.rb +2 -2
  41. data/lib/lutaml/lml/entity_types.rb +2 -2
  42. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  43. data/lib/lutaml/model/attribute.rb +11 -6
  44. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  45. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  46. data/lib/lutaml/model/global_context.rb +3 -5
  47. data/lib/lutaml/model/instrumentation.rb +0 -3
  48. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  49. data/lib/lutaml/model/register.rb +20 -31
  50. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  51. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  52. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  53. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  54. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  55. data/lib/lutaml/model/serialize/deserialization_context.rb +21 -0
  56. data/lib/lutaml/model/serialize/initialization.rb +19 -9
  57. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  58. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  59. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  60. data/lib/lutaml/model/store.rb +10 -17
  61. data/lib/lutaml/model/toml.rb +0 -2
  62. data/lib/lutaml/model/transformation_registry.rb +3 -7
  63. data/lib/lutaml/model/version.rb +1 -1
  64. data/lib/lutaml/model.rb +3 -19
  65. data/lib/lutaml/toml/format.rb +4 -8
  66. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  67. data/lib/lutaml/xml/adapter.rb +0 -4
  68. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  69. data/lib/lutaml/xml/builder/base.rb +0 -3
  70. data/lib/lutaml/xml/builder.rb +0 -8
  71. data/lib/lutaml/xml/data_model.rb +1 -1
  72. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  73. data/lib/lutaml/xml/format.rb +22 -74
  74. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  75. data/lib/lutaml/xml/model_transform.rb +14 -24
  76. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  77. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  78. data/lib/lutaml/xml/schema/builder.rb +6 -9
  79. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  80. data/lib/lutaml/xml/xml_element.rb +3 -2
  81. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  82. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  83. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  84. data/lib/tasks/performance_comparator.rb +1 -1
  85. data/lutaml-model.gemspec +3 -8
  86. data/spec/address_person_spec.rb +8 -0
  87. data/spec/address_spec.rb +4 -0
  88. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  89. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  90. data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
  91. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  92. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  93. data/spec/lutaml/model/cdata_spec.rb +2 -15
  94. data/spec/lutaml/model/encoding_spec.rb +0 -9
  95. data/spec/lutaml/model/except_spec.rb +0 -7
  96. data/spec/lutaml/model/json_spec.rb +0 -14
  97. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  98. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  99. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  100. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  101. data/spec/lutaml/model/serializable_spec.rb +0 -2
  102. data/spec/lutaml/model/serialize/deserialization_context_spec.rb +68 -0
  103. data/spec/lutaml/model/toml_spec.rb +0 -23
  104. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  105. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  106. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  107. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  108. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  109. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  110. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  111. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  112. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  113. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  114. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  115. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  116. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  117. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  118. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  119. data/spec/lutaml/xml/xml_spec.rb +2 -88
  120. data/spec/spec_helper.rb +8 -28
  121. data/spec/support/test_adapter_config.rb +6 -6
  122. metadata +2 -32
  123. data/.github/workflows/js-pr-check.yml +0 -106
  124. data/.github/workflows/js-sync.yml +0 -55
  125. data/.github/workflows/opal.yml +0 -65
  126. data/.gitmodules +0 -6
  127. data/.rspec-opal +0 -5
  128. data/docs/_guides/opal.adoc +0 -232
  129. data/lib/compat/opal/generate_boot.rb +0 -137
  130. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  131. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  132. data/lib/compat/opal/monitor.rb +0 -31
  133. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  134. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  135. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  136. data/lib/compat/opal/moxml_boot.rb +0 -68
  137. data/lib/compat/opal/objectspace_shim.rb +0 -23
  138. data/lib/compat/opal/rexml/namespace.rb +0 -59
  139. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  140. data/lib/compat/opal/rexml/source.rb +0 -214
  141. data/lib/compat/opal/rexml/text.rb +0 -426
  142. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  143. data/lib/compat/opal/rexml_compat.rb +0 -85
  144. data/lib/compat/opal/yaml_compat.rb +0 -32
  145. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  146. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  147. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  148. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  149. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  150. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  151. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  152. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  153. data/spec/support/opal.rb +0 -9
@@ -11,7 +11,7 @@ class PerformanceComparator
11
11
  BENCH_SCRIPT = File.join(TMP_PERF_DIR, "benchmark_runner.rb")
12
12
 
13
13
  BENCHMARK_MATRIX = {
14
- xml: %i[nokogiri ox oga rexml],
14
+ xml: %i[nokogiri ox rexml],
15
15
  json: %i[standard_json multi_json oj yeptris],
16
16
  yaml: %i[standard_yaml yeptris],
17
17
  toml: %i[toml_rb tomlib teptris],
data/lutaml-model.gemspec CHANGED
@@ -23,8 +23,6 @@ Gem::Specification.new do |spec|
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the
25
25
  # RubyGem that have been added into git.
26
- # vendor/ is excluded so the opal-oga / opal-ruby-ll submodule checkouts
27
- # are not shipped in the published gem.
28
26
  spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
27
  `git ls-files -z`.split("\x0").reject do |f|
30
28
  f.match(%r{^(test|features|vendor/)/})
@@ -41,15 +39,12 @@ Gem::Specification.new do |spec|
41
39
  # 0.5.84 always passes XML_PARSE_HUGE to libxml2: very large documents
42
40
  # parse completely instead of being silently truncated at the 10 MB
43
41
  # input-buffer cap (lutaml-model#871).
44
- # moxml 0.6.0 removed the Opal surface (lutaml/moxml#516, the
45
- # cross-language program's phase 4); the CRuby facade faces this
42
+ # moxml 0.6.0 removed its JavaScript-runtime surface (lutaml/moxml#516,
43
+ # the cross-language program's phase 4); the CRuby facade faces this
46
44
  # gem uses are unchanged, and the full suite is green on the 0.6
47
45
  # line (6386/0 with 0.6.0 resolved). Owner call (2026-10-31):
48
46
  # forward-pin the 0.6 series, matching canon (lutaml/canon#298);
49
- # floored at 0.6.1 per the maintainer's directive. The Opal lane's
50
- # workspace-local 0.5.x pin is retired with this floor — it cannot
51
- # resolve against it — and the boot's lib/compat/opal append is
52
- # directory-guarded in the Rakefile for both lines.
47
+ # floored at 0.6.1 per the maintainer's directive.
53
48
  # 0.6.23: preprocess_entities stopped rewriting the declared
54
49
  # encoding of text payloads beginning with an XML declaration
55
50
  # (lutaml/moxml#604) — the text-emission verbatim contract
@@ -215,6 +215,10 @@ RSpec.describe AddressPersonSpec do
215
215
  end
216
216
 
217
217
  it "serializes to XML with a collection of persons" do
218
+ # leptris drops xmlns="" on no-namespace children of a
219
+ # default-namespaced parent (leptris/leptris#2294).
220
+ skip "leptris/leptris#2294" if Lutaml::Xml.moxml_engine == :leptris
221
+
218
222
  expected_xml = <<~XML
219
223
  <Address>
220
224
  <Country>USA</Country>
@@ -339,6 +343,10 @@ RSpec.describe AddressPersonSpec do
339
343
  end
340
344
 
341
345
  it "serializes to XML" do
346
+ # leptris drops xmlns="" on no-namespace children of a
347
+ # default-namespaced parent (leptris/leptris#2294).
348
+ skip "leptris/leptris#2294" if Lutaml::Xml.moxml_engine == :leptris
349
+
342
350
  expect(model.to_xml).to be_xml_equivalent_to(xml)
343
351
  end
344
352
 
data/spec/address_spec.rb CHANGED
@@ -104,6 +104,10 @@ RSpec.describe Address do
104
104
  end
105
105
 
106
106
  it "serializes to XML with a collection of persons" do
107
+ # leptris drops xmlns="" on no-namespace children of a
108
+ # default-namespaced parent (leptris/leptris#2294).
109
+ skip "leptris/leptris#2294" if Lutaml::Xml.moxml_engine == :leptris
110
+
107
111
  # W3C minimal-subtree principle: nsp1 namespace is declared at the LCA
108
112
  # (Person element) rather than repeated on each child element.
109
113
  expected_xml = <<~XML
@@ -42,7 +42,7 @@ RSpec.describe "XML adapter benchmark", :benchmark do
42
42
  GC.stat(:total_allocated_objects) - before
43
43
  end
44
44
 
45
- %i[nokogiri ox oga rexml leptris].each do |adapter|
45
+ %i[nokogiri ox rexml leptris].each do |adapter|
46
46
  it "#{adapter}: from_xml/to_xml i/s and allocations" do
47
47
  model = nil
48
48
  Lutaml::Model::Config.with_adapter(xml: adapter) do
@@ -106,11 +106,8 @@ RSpec.describe Lutaml::Json::Adapter::StandardAdapter do
106
106
  end
107
107
 
108
108
  describe Lutaml::Json::GeneratorOptions do
109
- # The derived half of the allowlist reads JSON::State, which Opal's JSON
110
- # shim does not define. BASE_PERMITTED is what the filter falls back to
111
- # there, so it has to stand on its own.
112
- # BASE_PERMITTED is the whole allowlist on Opal, whose JSON shim has no
113
- # State class for DERIVED_PERMITTED to read. So it has to stand alone
109
+ # BASE_PERMITTED is what the filter falls back to when JSON::State is
110
+ # not defined for DERIVED_PERMITTED to read. So it has to stand alone
114
111
  # against the real generator, not merely be a subset of something larger.
115
112
  it "permits only options the running generator actually accepts" do
116
113
  rejected = described_class::BASE_PERMITTED.reject do |key|
@@ -128,10 +125,10 @@ RSpec.describe Lutaml::Json::Adapter::StandardAdapter do
128
125
  expect(rejected).to eq([])
129
126
  end
130
127
 
131
- # Opal's JSON shim defines no State class, so DERIVED_PERMITTED is empty
132
- # there and the whole module must still load. Asserting that
133
- # BASE_PERMITTED contains some symbols does not exercise the guard; only
134
- # loading the file with JSON::State absent does.
128
+ # Without a JSON::State class DERIVED_PERMITTED is empty and the whole
129
+ # module must still load. Asserting that BASE_PERMITTED contains some
130
+ # symbols does not exercise the guard; only loading the file with
131
+ # JSON::State absent does.
135
132
  it "loads and still permits the base set when JSON::State is absent" do
136
133
  hide_const("JSON::State")
137
134
 
@@ -223,6 +223,128 @@ RSpec.describe "KV group-then-bulk hydration" do
223
223
  expect(ranged.from_hash("tags" => %w[a b]).tags).to eq(%w[a b])
224
224
  end
225
225
 
226
+ it "plans a class-level discriminator and hydrates concrete children" do
227
+ # The `_class` shape: a scalar attribute flagged polymorphic_class
228
+ # whose rule carries the class map. The discriminator is a scalar
229
+ # row; the concrete child class comes from each document.
230
+ shape = Class.new(Lutaml::Model::Serializable) do
231
+ attribute :kind, :string, polymorphic_class: true
232
+ attribute :name, :string
233
+ hsh do
234
+ map "kind", to: :kind, polymorphic_map: {
235
+ "KvGroup::Circle" => "KvGroup::Circle",
236
+ "KvGroup::Square" => "KvGroup::Square",
237
+ "KvGroup::Shape" => "KvGroup::Shape",
238
+ }
239
+ map "name", to: :name
240
+ end
241
+ end
242
+ circle = Class.new(shape) do
243
+ attribute :radius, :integer
244
+ hsh do
245
+ map "kind", to: :kind
246
+ map "name", to: :name
247
+ map "radius", to: :radius
248
+ end
249
+ end
250
+ square = Class.new(shape) do
251
+ attribute :side, :integer
252
+ hsh do
253
+ map "kind", to: :kind
254
+ map "name", to: :name
255
+ map "side", to: :side
256
+ end
257
+ end
258
+ sheet = Class.new(Lutaml::Model::Serializable) do
259
+ attribute :shapes, shape, collection: true
260
+ attribute :first, shape
261
+ hsh do
262
+ map "shapes", to: :shapes
263
+ map "first", to: :first
264
+ end
265
+ end
266
+ stub_const("KvGroup::Shape", shape)
267
+ stub_const("KvGroup::Circle", circle)
268
+ stub_const("KvGroup::Square", square)
269
+ stub_const("KvGroup::Sheet", sheet)
270
+
271
+ expect(shape.attributes[:kind].polymorphic?).to be(true)
272
+ expect(Lutaml::KeyValue::Transform.kv_group_plan(sheet, :hash,
273
+ :default)).to be_truthy
274
+
275
+ doc = {
276
+ "shapes" => [
277
+ { "kind" => "KvGroup::Circle", "name" => "c", "radius" => 2 },
278
+ { "kind" => "KvGroup::Square", "name" => "s", "side" => 3 },
279
+ # The fallthrough: an entry resolving to the declared type
280
+ # itself hydrates through the declared type's own rows.
281
+ { "kind" => "KvGroup::Shape", "name" => "bare" },
282
+ ],
283
+ "first" => { "kind" => "KvGroup::Square", "name" => "f", "side" => 1 },
284
+ }
285
+ sheet_built = sheet.from_hash(doc)
286
+
287
+ expect(sheet_built.shapes.map(&:class)).to eq([circle, square, shape])
288
+ expect(sheet_built.shapes.map(&:to_hash)).to eq(doc["shapes"])
289
+ expect(sheet_built.first).to be_a(square)
290
+ expect(sheet_built.first.side).to eq(1)
291
+ expect(sheet_built.shapes.first.lutaml_parent).to equal(sheet_built)
292
+ expect(sheet_built.to_hash).to eq(doc)
293
+ end
294
+
295
+ it "takes the walk per document when a discriminator names an ineligible class" do
296
+ shape = Class.new(Lutaml::Model::Serializable) do
297
+ attribute :kind, :string, polymorphic_class: true
298
+ hsh do
299
+ map "kind", to: :kind, polymorphic_map: {
300
+ "KvGroup::RangedShape" => "KvGroup::RangedShape",
301
+ "KvGroup::PlainShape" => "KvGroup::PlainShape",
302
+ }
303
+ end
304
+ end
305
+ ranged_shape = Class.new(shape) do
306
+ attribute :tags, :string, collection: 1..2
307
+ hsh do
308
+ map "kind", to: :kind
309
+ map "tags", to: :tags
310
+ end
311
+ end
312
+ plain_shape = Class.new(shape) do
313
+ attribute :label, :string
314
+ hsh do
315
+ map "kind", to: :kind
316
+ map "label", to: :label
317
+ end
318
+ end
319
+ sheet = Class.new(Lutaml::Model::Serializable) do
320
+ attribute :shapes, shape, collection: true
321
+ hsh { map "shapes", to: :shapes }
322
+ end
323
+ stub_const("KvGroup::ShapeBase", shape)
324
+ stub_const("KvGroup::RangedShape", ranged_shape)
325
+ stub_const("KvGroup::PlainShape", plain_shape)
326
+ stub_const("KvGroup::MixedSheet", sheet)
327
+
328
+ # The holder is eligible; the ineligible concrete class is a
329
+ # per-document verdict (its range collection keeps the walk).
330
+ expect(Lutaml::KeyValue::Transform.kv_group_plan(sheet, :hash,
331
+ :default)).to be_truthy
332
+ expect(Lutaml::KeyValue::Transform.kv_group_plan(ranged_shape, :hash,
333
+ :default)).to be(false)
334
+ expect(Lutaml::KeyValue::Transform.kv_group_plan(plain_shape, :hash,
335
+ :default)).to be_truthy
336
+
337
+ doc = { "shapes" => [
338
+ { "kind" => "KvGroup::RangedShape", "tags" => %w[a b] },
339
+ { "kind" => "KvGroup::PlainShape", "label" => "p" },
340
+ ] }
341
+ built = sheet.from_hash(doc)
342
+
343
+ expect(built.shapes.map(&:class)).to eq([ranged_shape, plain_shape])
344
+ expect(built.shapes.map(&:to_hash)).to eq(doc["shapes"])
345
+ expect(built.to_hash).to eq(doc)
346
+ end
347
+
226
348
  it "compiles self-referential models as a plan referencing itself (#1297)" do
227
349
  node = Class.new(Lutaml::Model::Serializable) do
228
350
  attribute :name, :string
@@ -311,5 +433,86 @@ RSpec.describe "KV group-then-bulk hydration" do
311
433
  end
312
434
  end
313
435
  end
314
-
436
+
437
+ # #1311 levers 1 and 2: absent keys take a compiled per-row action
438
+ # instead of the per-rule walk, and custom-initialize classes
439
+ # construct against the compiled walk seed (the #1059 contract)
440
+ # rather than the generic attribute walk.
441
+ describe "absent-key actions and walk-seed construction" do
442
+ let(:model_class) do
443
+ Class.new(Lutaml::Model::Serializable) do
444
+ attribute :plain, :string
445
+ attribute :with_default, :string, default: "d"
446
+ attribute :items, :string, collection: true, initialize_empty: true
447
+ attribute :plain_items, :string, collection: true
448
+
449
+ key_value do
450
+ map "plain", to: :plain
451
+ map "with_default", to: :with_default
452
+ map "items", to: :items
453
+ map "plain_items", to: :plain_items
454
+ end
455
+ end
456
+ end
457
+
458
+ before { stub_const("KvGroup::Absent", model_class) }
459
+
460
+ it "seeds absent defaults through the writer, as the per-rule walk does" do
461
+ model = KvGroup::Absent.from_hash({})
462
+
463
+ expect(model.with_default).to eq("d")
464
+ expect(model.using_default?(:with_default)).to be(false)
465
+ expect(model.using_default?(:plain)).to be(false)
466
+ expect(model.items).to eq([])
467
+ expect(model.plain_items).to be_nil
468
+ expect(model.to_hash).to eq({ "with_default" => "d" })
469
+ end
470
+
471
+ it "keeps the writer outcome for a present-nil key" do
472
+ model = KvGroup::Absent.from_hash({ "plain" => nil })
473
+
474
+ expect(model.plain).to be_nil
475
+ expect(model.using_default?(:plain)).to be(false)
476
+ expect(model.to_hash).to eq({ "with_default" => "d" })
477
+ end
478
+
479
+ it "routes absent keys through the walk when value-map overrides are given" do
480
+ model = KvGroup::Absent.from_hash({}, omitted: :empty)
481
+
482
+ expect(model.plain).to eq("")
483
+ expect(model.using_default?(:plain)).to be(false)
484
+ # An empty string is dropped from the serialized form (render_empty
485
+ # is off by default), exactly as the per-rule walk renders it.
486
+ expect(model.to_hash).to eq({ "with_default" => "d" })
487
+ end
488
+
489
+ it "runs a custom initialize against the compiled walk seed" do
490
+ custom = Class.new(Lutaml::Model::Serializable) do
491
+ attribute :a, :string
492
+ attribute :b, :string, default: "d"
493
+ attribute :items, :string, collection: true, initialize_empty: true
494
+
495
+ key_value do
496
+ map "a", to: :a
497
+ map "b", to: :b
498
+ map "items", to: :items
499
+ end
500
+
501
+ attr_reader :seen
502
+
503
+ def initialize(options = {})
504
+ super
505
+ @seen = [a, b, items]
506
+ end
507
+ end
508
+ stub_const("KvGroup::CustomInit", custom)
509
+
510
+ model = KvGroup::CustomInit.from_hash({ "a" => "x" })
511
+
512
+ expect(model.seen).to eq([nil, "d", []])
513
+ expect(model.a).to eq("x")
514
+ expect(model.b).to eq("d")
515
+ expect(model.to_hash).to eq({ "a" => "x", "b" => "d" })
516
+ end
517
+ end
315
518
  end
@@ -51,8 +51,6 @@ RSpec.describe "yeptris engine preference" do
51
51
  end
52
52
 
53
53
  def yeptris_engine_available?
54
- return false if RUBY_ENGINE == "opal"
55
-
56
54
  Lutaml::Model::Utils.safe_load("yeptris", :Yeptris)
57
55
  end
58
56
 
@@ -66,31 +66,17 @@ RSpec.describe Lutaml::Model::CachedTypeResolver do
66
66
  it_behaves_like "a resolver cache backend"
67
67
  end
68
68
 
69
- describe described_class::MutexHashCache do
70
- subject(:cache_backend) { described_class.new }
71
-
72
- it_behaves_like "a resolver cache backend"
73
- end
74
-
75
69
  describe "#initialize" do
76
70
  it "stores the delegate resolver" do
77
71
  expect(resolver.delegate).to eq(Lutaml::Model::TypeResolver)
78
72
  end
79
73
 
80
- it "uses ConcurrentMapCache by default on native Ruby" do
74
+ it "uses ConcurrentMapCache by default" do
81
75
  expect(resolver.cache_backend).to be_a(described_class::ConcurrentMapCache)
82
76
  end
83
77
 
84
- it "uses MutexHashCache by default on Opal" do
85
- allow(Lutaml::Model::RuntimeCompatibility).to receive(:opal?).and_return(true)
86
-
87
- opal_resolver = described_class.new(delegate: Lutaml::Model::TypeResolver)
88
-
89
- expect(opal_resolver.cache_backend).to be_a(described_class::MutexHashCache)
90
- end
91
-
92
78
  it "accepts an injected cache backend" do
93
- cache_backend = described_class::MutexHashCache.new
79
+ cache_backend = described_class::ConcurrentMapCache.new
94
80
 
95
81
  injected_resolver = described_class.new(
96
82
  delegate: Lutaml::Model::TypeResolver,
@@ -321,42 +307,4 @@ RSpec.describe Lutaml::Model::CachedTypeResolver do
321
307
  expect(stats[:keys]).to contain_exactly(%i[ctx2 custom])
322
308
  end
323
309
  end
324
-
325
- describe "Opal compatibility" do
326
- let(:resolver) { described_class.new(delegate: Lutaml::Model::TypeResolver) }
327
-
328
- before do
329
- allow(Lutaml::Model::RuntimeCompatibility).to receive(:opal?).and_return(true)
330
- end
331
-
332
- it "uses the MutexHashCache by default on Opal" do
333
- expect(resolver.cache_backend).to be_a(described_class::MutexHashCache)
334
- end
335
-
336
- it "does not autoload the native ConcurrentMapCache on Opal" do
337
- hide_const("Lutaml::Model::CachedTypeResolver::ConcurrentMapCache")
338
-
339
- load File.expand_path(
340
- "../../../lib/lutaml/model/cached_type_resolver.rb", __dir__
341
- )
342
-
343
- expect(described_class.autoload?(:ConcurrentMapCache)).to be_nil
344
- end
345
-
346
- it "caches resolved types without Concurrent::Map" do
347
- resolver.resolve(:custom, context)
348
- registry.clear
349
-
350
- expect(resolver.resolve(:custom, context)).to eq(custom_class)
351
- expect(resolver.cache_stats[:keys]).to eq([%i[test custom]])
352
- end
353
-
354
- it "clears the Opal cache" do
355
- resolver.resolve(:custom, context)
356
-
357
- resolver.clear_all_caches
358
-
359
- expect(resolver.cache_stats[:size]).to eq(0)
360
- end
361
- end
362
310
  end
@@ -335,17 +335,6 @@ RSpec.describe CdataSpec do
335
335
  XML
336
336
  end
337
337
 
338
- let(:expected_oga_xml) do
339
- "<CustomModelParent>" \
340
- "<first_name><![CDATA[John]]></first_name>" \
341
- "<last_name>Doe</last_name>" \
342
- "<CustomModelChild>" \
343
- "<street><![CDATA[Oxford Street]]></street>" \
344
- "<city><![CDATA[London]]></city>" \
345
- "</CustomModelChild>" \
346
- "</CustomModelParent>"
347
- end
348
-
349
338
  describe ".from_xml" do
350
339
  it "maps XML content to custom model using custom methods" do
351
340
  instance = parent_mapper.from_xml(input_xml)
@@ -366,9 +355,7 @@ RSpec.describe CdataSpec do
366
355
  instance = parent_mapper.from_xml(input_xml)
367
356
  result_xml = parent_mapper.to_xml(instance)
368
357
 
369
- expected_output = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga)
370
- expected_oga_xml
371
- elsif adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
358
+ expected_output = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
372
359
  expected_ox_xml
373
360
  else
374
361
  expected_nokogiri_xml
@@ -570,7 +557,7 @@ RSpec.describe CdataSpec do
570
557
  end
571
558
  end
572
559
 
573
- %i[nokogiri ox oga rexml].each do |engine|
560
+ %i[nokogiri ox rexml].each do |engine|
574
561
  next unless TestAdapterConfig.adapter_enabled?(engine)
575
562
 
576
563
  describe "the :#{engine} lane" do
@@ -269,13 +269,4 @@ RSpec.describe "XML Encoding Handling" do
269
269
  end
270
270
  end
271
271
  end
272
-
273
- if defined?(Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga))
274
- describe "with Oga adapter" do
275
- if TestAdapterConfig.adapter_enabled?(:oga)
276
- it_behaves_like "encoding behavior",
277
- Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga)
278
- end
279
- end
280
- end
281
272
  end
@@ -215,13 +215,6 @@ RSpec.describe "Except" do
215
215
  it_behaves_like "xml", described_class
216
216
  end
217
217
 
218
- describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
219
- if TestAdapterConfig.adapter_enabled?(:oga)
220
- it_behaves_like "xml",
221
- described_class
222
- end
223
- end
224
-
225
218
  describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox) do
226
219
  if TestAdapterConfig.adapter_enabled?(:ox)
227
220
  it_behaves_like "xml",
@@ -15,18 +15,4 @@ RSpec.describe Lutaml::Model::Json do
15
15
  expect(result).to include("ok")
16
16
  end
17
17
  end
18
-
19
- describe "adapter autoloading" do
20
- it "does not autoload native JSON adapters on Opal" do
21
- %i[OjAdapter MultiJsonAdapter].each do |constant_name|
22
- hide_const("Lutaml::Json::Adapter::#{constant_name}")
23
- end
24
-
25
- allow(Lutaml::Model::RuntimeCompatibility).to receive(:opal?).and_return(true)
26
- load File.expand_path("../../../lib/lutaml/json/adapter.rb", __dir__)
27
-
28
- expect(Lutaml::Json::Adapter.autoload?(:OjAdapter)).to be_nil
29
- expect(Lutaml::Json::Adapter.autoload?(:MultiJsonAdapter)).to be_nil
30
- end
31
- end
32
18
  end
@@ -803,7 +803,7 @@ RSpec.describe "MixedContent" do
803
803
  describe ".from_xml" do
804
804
  let(:expected_nokogiri_content) do
805
805
  # Moxml resolves numeric character references (&#x2014;, &#xA9;) to
806
- # their Unicode characters, matching Oga/Rexml behavior. Raw Nokogiri
806
+ # their Unicode characters, matching the Rexml behavior. Raw Nokogiri
807
807
  # preserved numeric refs via native serialization, but the resolved
808
808
  # form is semantically identical.
809
809
  "B <p>R&amp;C</p>\n C <p>J\u{2014}C</p>\n O <p>A &amp; B </p>\n F <p>Z \u{A9}S</p>"
@@ -811,9 +811,6 @@ RSpec.describe "MixedContent" do
811
811
  let(:expected_ox_content) do
812
812
  "B <p>R&amp;C</p> C <p>J—C</p> O <p>A &amp; B </p> F <p>Z ©S</p>"
813
813
  end
814
- let(:expected_oga_content) do
815
- "B <p>R&amp;C</p>\n C <p>J—C</p>\n O <p>A &amp; B </p>\n F <p>Z ©S</p>"
816
- end
817
814
  let(:expected_rexml_content) do
818
815
  "B <p>R&amp;C</p>\n C <p>J—C</p>\n O <p>A &amp; B </p>\n F <p>Z ©S</p>"
819
816
  end
@@ -851,18 +848,6 @@ RSpec.describe "MixedContent" do
851
848
  XML
852
849
  end
853
850
 
854
- let(:expected_oga_xml) do
855
- <<~XML
856
- <SpecialCharContentWithRawOptionAndMixedOption>
857
- <special> B <p>R&amp;C</p>
858
- C <p>J—C</p>
859
- O <p>A &amp; B </p>
860
- F <p>Z ©S</p>
861
- </special>
862
- </SpecialCharContentWithRawOptionAndMixedOption>
863
- XML
864
- end
865
-
866
851
  let(:expected_rexml_xml) do
867
852
  <<~XML
868
853
  <SpecialCharContentWithRawOptionAndMixedOption>
@@ -881,9 +866,9 @@ RSpec.describe "MixedContent" do
881
866
 
882
867
  expected_xml = send(:"expected_#{adapter_class.type}_xml")
883
868
 
884
- # Ox and Oga normalize whitespace in mixed content per XML spec (semantically equivalent)
869
+ # Ox normalizes whitespace in mixed content per XML spec (semantically equivalent)
885
870
  # Canon can't compare whitespace-normalized XML, so we normalize both sides
886
- if [Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox), Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga)].include?(adapter_class)
871
+ if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
887
872
  normalize = ->(str) {
888
873
  str.gsub(/\s+/, " ").gsub(/\s*</, "<").gsub(/>\s*/, ">").strip
889
874
  }
@@ -921,7 +906,6 @@ RSpec.describe "MixedContent" do
921
906
  describe ".to_xml" do
922
907
  let(:expected_nokogiri_xml) { "B <p>R&amp;C</p>" }
923
908
  let(:expected_ox_xml) { "B <p>R&amp;C</p>" }
924
- let(:expected_oga_xml) { "B <p>R&amp;C</p>" }
925
909
  let(:expected_rexml_xml) { "B <p>R&amp;C</p>" }
926
910
 
927
911
  it "serializes special char mixed content correctly" do
@@ -958,9 +942,6 @@ RSpec.describe "MixedContent" do
958
942
  let(:expected_xml) do
959
943
  "<TextualSupport>\n <value>&lt;computer security&gt; type of operation specified by an access right</value>\n</TextualSupport>"
960
944
  end
961
- let(:expected_oga_xml) do
962
- "<TextualSupport><value>&lt;computer security&gt; type of operation specified by an access right</value></TextualSupport>"
963
- end
964
945
 
965
946
  it "serializes special char mixed content correctly" do
966
947
  parsed = MixedContentSpec::TextualSupport.from_xml(xml)
@@ -1007,16 +988,12 @@ RSpec.describe "MixedContent" do
1007
988
 
1008
989
  context "when encoding: nil xml" do
1009
990
  let(:expected_encoding_nil_nokogiri_xml) do
1010
- # Moxml resolves numeric character references to Unicode,
1011
- # matching Oga/Rexml behavior (see expected_encoding_nil_oga_xml).
991
+ # Moxml resolves numeric character references to Unicode.
1012
992
  "\u{2211}computer security\u{220F} type of \u{200B} operation specified \u{B5} by an access right"
1013
993
  end
1014
994
  let(:expected_encoding_nil_ox_xml) do
1015
995
  "<HexCode> \xE2\x88\x91computer security\xE2\x88\x8F type of \xE2\x80\x8B operation specified \xC2\xB5 by an access right </HexCode>\n".force_encoding("ASCII-8BIT")
1016
996
  end
1017
- let(:expected_encoding_nil_oga_xml) do
1018
- "<HexCode>\n ∑computer security∏ type of ​ operation specified µ by an access right\n</HexCode>"
1019
- end
1020
997
 
1021
998
  it "serializes special char mixed content correctly with encoding: nil to get hexcode" do
1022
999
  parsed = MixedContentSpec::HexCode.from_xml(xml, encoding: nil)
@@ -1026,8 +1003,6 @@ RSpec.describe "MixedContent" do
1026
1003
  expected_encoding_nil_nokogiri_xml
1027
1004
  elsif adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:ox)
1028
1005
  expected_encoding_nil_ox_xml
1029
- else
1030
- expected_encoding_nil_oga_xml
1031
1006
  end
1032
1007
 
1033
1008
  expect(parsed.encoding).to be_nil
@@ -1078,11 +1053,7 @@ RSpec.describe "MixedContent" do
1078
1053
  parsed = MixedContentSpec::Shift.from_xml(fixture,
1079
1054
  encoding: "Shift_JIS")
1080
1055
  serialized = parsed.to_xml
1081
- expected = if adapter_class.type == "oga"
1082
- fixture.gsub(/\s+/, "")
1083
- else
1084
- fixture.strip
1085
- end
1056
+ expected = fixture.strip
1086
1057
  expect(serialized.strip).to eq(expected)
1087
1058
  end
1088
1059
 
@@ -1155,11 +1126,7 @@ RSpec.describe "MixedContent" do
1155
1126
  parsed = MixedContentSpec::Latin.from_xml(fixture,
1156
1127
  encoding: "ISO-8859-1")
1157
1128
  serialized = parsed.to_xml
1158
- expected_xml = if adapter_class == Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga)
1159
- "<note><to>José</to><from>Müller</from><heading>Reminder</heading></note>"
1160
- else
1161
- "<note>\n <to>José</to>\n <from>Müller</from>\n <heading>Reminder</heading>\n</note>"
1162
- end
1129
+ expected_xml = "<note>\n <to>José</to>\n <from>Müller</from>\n <heading>Reminder</heading>\n</note>"
1163
1130
  expect(serialized.encode("UTF-8").strip).to be_xml_equivalent_to(expected_xml.encode("UTF-8"))
1164
1131
  end
1165
1132
  end
@@ -1491,13 +1458,6 @@ RSpec.describe "MixedContent" do
1491
1458
  end
1492
1459
  end
1493
1460
 
1494
- describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
1495
- if TestAdapterConfig.adapter_enabled?(:oga)
1496
- it_behaves_like "mixed content behavior",
1497
- described_class
1498
- end
1499
- end
1500
-
1501
1461
  describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
1502
1462
  if TestAdapterConfig.adapter_enabled?(:rexml)
1503
1463
  it_behaves_like "mixed content behavior",
@@ -196,13 +196,6 @@ RSpec.describe "OrderedContent" do
196
196
  end
197
197
  end
198
198
 
199
- describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
200
- if TestAdapterConfig.adapter_enabled?(:oga)
201
- it_behaves_like "ordered content behavior",
202
- described_class
203
- end
204
- end
205
-
206
199
  describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
207
200
  if TestAdapterConfig.adapter_enabled?(:rexml)
208
201
  it_behaves_like "ordered content behavior",
@@ -357,12 +357,6 @@ RSpec.describe "Processing Instructions" do
357
357
  end
358
358
  end
359
359
 
360
- describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:oga) do
361
- if TestAdapterConfig.adapter_enabled?(:oga)
362
- it_behaves_like "PI round-trip behavior", described_class
363
- end
364
- end
365
-
366
360
  describe Lutaml::Xml::Adapter::MoxmlAdapter.for_engine(:rexml) do
367
361
  if TestAdapterConfig.adapter_enabled?(:rexml)
368
362
  it_behaves_like "PI round-trip behavior", described_class