lutaml-model 0.8.199 → 0.8.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/docs/_references/plan-schema-spec.adoc +20 -0
- data/lib/lutaml/key_value/transform.rb +236 -107
- data/lib/lutaml/model/attribute.rb +14 -2
- data/lib/lutaml/model/schema/xml_compiler/spec_builder.rb +7 -8
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/schema/xsd/override.rb +63 -22
- data/lib/lutaml/xml/schema/xsd/schema.rb +22 -19
- data/spec/lml/lml_spec_setup.rb +9 -6
- data/spec/lutaml/key_value/group_instantiate_spec.rb +11 -6
- data/spec/lutaml/key_value/recursive_plan_spec.rb +163 -0
- data/spec/lutaml/model/polymorphic_scalar_member_spec.rb +57 -0
- data/spec/lutaml/xml/schema/xsd_override_assembly_spec.rb +116 -39
- data/spec/lutaml/xml/schema/xsd_override_cycle_spec.rb +150 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: '0499659ca4f9da568095087ed451503ced3992c62bf056b06bd268398cb2a609'
|
|
4
|
+
data.tar.gz: cf53f475ba4d0e0d6d7dc0ced4793e0f9a07e09b585113cf4fa1c8b81c517bcf
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 17890881efe1ae3bdf15c996b1da9bf660932cef57abc3ca0f6f87a584e3150d12b9615435ae1151864cb8f6ee4711f47bed27cd7b450723cfb7f820ead542c7
|
|
7
|
+
data.tar.gz: 6b7e93f724efba2c00fd528b94a34f465bd8bcd8e49b64a7e41fb741e9395b59635454090ff94867a101d3da7233114c77fb2a79da17716f3307c8d6b8f106d8
|
|
@@ -150,6 +150,16 @@ The in-memory precedent for this tuple is the shipped row shape
|
|
|
150
150
|
replaces the Ruby object references (rule, attr, type, class) with
|
|
151
151
|
portable identifiers.
|
|
152
152
|
|
|
153
|
+
The plan graph is a graph, not a tree. A recursive model graph — a tree
|
|
154
|
+
whose nodes reference their own type, directly or through other model
|
|
155
|
+
types — compiles as a self-referential plan: the `model` row's nested
|
|
156
|
+
plan reference may be the enclosing plan. The wire form therefore
|
|
157
|
+
identifies each plan and references plans by identifier; it never
|
|
158
|
+
expands a nested plan inline, which would be unbounded for a tree shape
|
|
159
|
+
(#1297). A plan compile session commits its plans only when the
|
|
160
|
+
outermost build succeeds, so a plan that references rows an incomplete
|
|
161
|
+
outer build never finished is never published.
|
|
162
|
+
|
|
153
163
|
=== Row kinds (XML lane; extracted from the shipped kinds)
|
|
154
164
|
|
|
155
165
|
The XML lane's compiled kinds are already enumerated in code
|
|
@@ -210,6 +220,16 @@ unmapped merges exactly as `kv_group_build` does today. The
|
|
|
210
220
|
Ruby-visible object graph, validation surface, and error classes are
|
|
211
221
|
byte-for-byte the fallback's.
|
|
212
222
|
|
|
223
|
+
Executor contract (the reference the crate's executor mirrors): the
|
|
224
|
+
plan runs on an explicit frame stack, one frame per model under
|
|
225
|
+
construction, so hydration depth is bound by the heap and never by the
|
|
226
|
+
VM stack (#1297). Children complete before the parent instance is
|
|
227
|
+
constructed; siblings hydrate in row order and collection items in
|
|
228
|
+
document order; each child is linked to its parent, and to its root
|
|
229
|
+
when it has none, once the parent instance exists. A child shape the
|
|
230
|
+
plan does not cover unwinds the whole build to the fallback, which owns
|
|
231
|
+
that shape's semantics and errors.
|
|
232
|
+
|
|
213
233
|
Parse errors: the engine raises the strict-parse contract (the
|
|
214
234
|
`strict:` kwarg lineage — malformed input is a format error, never a
|
|
215
235
|
best-effort tree), mapped to `Lutaml::Model::InvalidFormatError` at
|
|
@@ -152,10 +152,10 @@ module Lutaml
|
|
|
152
152
|
# ---- TODO.max-perf/37: group-then-instantiate fast path ----
|
|
153
153
|
|
|
154
154
|
# [model class, format, register] -> rows or false (ineligible).
|
|
155
|
-
# Rows: [[rule, attr, kind, child_rows]] with kind
|
|
156
|
-
# :model; child_rows is the child
|
|
157
|
-
#
|
|
158
|
-
#
|
|
155
|
+
# Rows: [[rule, attr, kind, child_rows, child_register]] with kind
|
|
156
|
+
# :scalar, :model, :child_map or :unmapped; child_rows is the child
|
|
157
|
+
# model's own row set. A recursive model graph compiles as a
|
|
158
|
+
# self-referential plan: child_rows may be the plan itself.
|
|
159
159
|
# Concurrent::Map under threaded MRI, plain Hash under Opal
|
|
160
160
|
# (Concurrent is unavailable there) — the RULE_RECORDS pattern.
|
|
161
161
|
# Writes are idempotent (the same deterministic plan is computed),
|
|
@@ -193,24 +193,43 @@ module Lutaml
|
|
|
193
193
|
plan = KV_GROUP_PLANS[key]
|
|
194
194
|
return plan unless plan.nil?
|
|
195
195
|
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
#
|
|
200
|
-
#
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
196
|
+
# A recursive model graph (a tree: the model references itself,
|
|
197
|
+
# directly or through other models) compiles as a
|
|
198
|
+
# self-referential plan: the build in progress publishes its row
|
|
199
|
+
# list to the builds it spawns, so the cycle point references
|
|
200
|
+
# the same rows instead of refusing the model (#1297). Both the
|
|
201
|
+
# publication and the session's results are thread-local: a
|
|
202
|
+
# concurrent build never sees them, and a session commits only
|
|
203
|
+
# when its outermost build succeeds — an inner plan referencing
|
|
204
|
+
# rows a failed outer build never finished must not survive.
|
|
205
|
+
building = (Thread.current[:kv_group_plan_building] ||= {})
|
|
206
|
+
return building[key] if building.key?(key)
|
|
207
|
+
|
|
208
|
+
rows = []
|
|
209
|
+
building[key] = rows
|
|
205
210
|
begin
|
|
206
|
-
|
|
207
|
-
|
|
211
|
+
built = build_kv_group_plan(model_class, format, register, rows)
|
|
212
|
+
(Thread.current[:kv_group_plan_session] ||= []) << [key, built]
|
|
208
213
|
ensure
|
|
209
|
-
|
|
214
|
+
building.delete(key)
|
|
215
|
+
if building.empty?
|
|
216
|
+
session = Thread.current[:kv_group_plan_session]
|
|
217
|
+
Thread.current[:kv_group_plan_session] = nil
|
|
218
|
+
# Only the outermost verdict decides: an inner plan that
|
|
219
|
+
# completed references the outer rows, so a failed outer
|
|
220
|
+
# build (false, an exception) commits nothing at all. A
|
|
221
|
+
# concurrent build that committed first keeps its plan.
|
|
222
|
+
if built
|
|
223
|
+
session&.each do |built_key, result|
|
|
224
|
+
KV_GROUP_PLANS[built_key] = result unless KV_GROUP_PLANS.key?(built_key)
|
|
225
|
+
end
|
|
226
|
+
end
|
|
227
|
+
end
|
|
210
228
|
end
|
|
229
|
+
built
|
|
211
230
|
end
|
|
212
231
|
|
|
213
|
-
def self.build_kv_group_plan(model_class, format, register)
|
|
232
|
+
def self.build_kv_group_plan(model_class, format, register, rows = [])
|
|
214
233
|
return false unless model_class.is_a?(Class) &&
|
|
215
234
|
model_class.include?(Lutaml::Model::Serialize)
|
|
216
235
|
|
|
@@ -229,8 +248,6 @@ module Lutaml
|
|
|
229
248
|
"map_unmapped target :#{unmapped_target} is not a " \
|
|
230
249
|
"declared attribute of #{model_class}"
|
|
231
250
|
end
|
|
232
|
-
rows = nil
|
|
233
|
-
claimed = nil
|
|
234
251
|
mapping.mappings(register).each do |rule|
|
|
235
252
|
eligible = !rule.name.nil? && !rule.multiple_mappings? &&
|
|
236
253
|
rule.delegate.nil? &&
|
|
@@ -274,7 +291,6 @@ module Lutaml
|
|
|
274
291
|
rule.hash_mappings)
|
|
275
292
|
return false unless child_plan
|
|
276
293
|
|
|
277
|
-
rows ||= []
|
|
278
294
|
rows << [rule, attr, :child_map, child_plan, nil, nil]
|
|
279
295
|
next
|
|
280
296
|
end
|
|
@@ -285,7 +301,6 @@ module Lutaml
|
|
|
285
301
|
child_rows = kv_group_plan(type, format, child_register)
|
|
286
302
|
return false unless child_rows
|
|
287
303
|
|
|
288
|
-
rows ||= []
|
|
289
304
|
# child_register rides the row: the plan was BUILT under it,
|
|
290
305
|
# and rebuilding the resolution per model row per document
|
|
291
306
|
# cost a Concurrent::Map hop each time (TODO.perf 14).
|
|
@@ -293,7 +308,6 @@ module Lutaml
|
|
|
293
308
|
elsif type.is_a?(Class) && type < Lutaml::Model::Type::Value &&
|
|
294
309
|
!attr.value_policy.whole_value?(type) &&
|
|
295
310
|
!Lutaml::Model::Attribute.custom_from_probe?(type)
|
|
296
|
-
rows ||= []
|
|
297
311
|
rows << [rule, attr, :scalar, nil, nil, nil]
|
|
298
312
|
else
|
|
299
313
|
return false
|
|
@@ -305,11 +319,10 @@ module Lutaml
|
|
|
305
319
|
Array(rule.name).each { |name| claimed[name.to_s] = true } if rule.name
|
|
306
320
|
end
|
|
307
321
|
claimed.freeze
|
|
308
|
-
|
|
309
|
-
nil]
|
|
322
|
+
rows << [nil, nil, :unmapped, unmapped_target, claimed, nil]
|
|
310
323
|
end
|
|
311
324
|
# No eligible rows at all (empty mapping) — nothing to gain.
|
|
312
|
-
rows
|
|
325
|
+
rows.empty? ? nil : rows
|
|
313
326
|
end
|
|
314
327
|
|
|
315
328
|
# Class-level twin of the walk's child-map compile: the registry
|
|
@@ -338,30 +351,150 @@ child_mappings)
|
|
|
338
351
|
nil
|
|
339
352
|
end
|
|
340
353
|
|
|
354
|
+
# One model under construction by the explicit-stack group build:
|
|
355
|
+
# its row scan, the positional values collected so far and the
|
|
356
|
+
# child frame it needs next. One frame per nesting level, reused
|
|
357
|
+
# across siblings, so hydration depth is bound by the heap rather
|
|
358
|
+
# than the VM stack (#1297).
|
|
359
|
+
GroupBuildFrame = ::Struct.new(
|
|
360
|
+
:transform, :rows, :doc, :format, :register, :options,
|
|
361
|
+
:slots, :children, :absent, :unmapped, :index,
|
|
362
|
+
:pending_index, :pending_items, :pending_cursor, :pending_built,
|
|
363
|
+
:request_transform, :request_rows, :request_register, :request_doc,
|
|
364
|
+
:instance
|
|
365
|
+
) do
|
|
366
|
+
def start(transform, rows, doc, format, register, options)
|
|
367
|
+
self.transform = transform
|
|
368
|
+
self.rows = rows
|
|
369
|
+
self.doc = doc
|
|
370
|
+
self.format = format
|
|
371
|
+
self.register = register
|
|
372
|
+
self.options = options
|
|
373
|
+
# Positional values, not per-row [name, value] pairs: rows are
|
|
374
|
+
# a fixed per-class list, so the writer to apply lives at the
|
|
375
|
+
# row's index and the pair arrays were the lane's biggest
|
|
376
|
+
# allocation (~6 arrays per node on hydrate-heavy corpora).
|
|
377
|
+
self.slots = Array.new(rows.size, MISSING)
|
|
378
|
+
# Lazy: the scalar hot path never pushes a child; the shared
|
|
379
|
+
# wiring pass tolerates nil.
|
|
380
|
+
self.children = nil
|
|
381
|
+
# Lazy: the present-key hot path never pushes, and this runs
|
|
382
|
+
# once per hydrated model instance.
|
|
383
|
+
self.absent = nil
|
|
384
|
+
self.unmapped = nil
|
|
385
|
+
self.index = 0
|
|
386
|
+
clear_pending
|
|
387
|
+
self.instance = nil
|
|
388
|
+
self
|
|
389
|
+
end
|
|
390
|
+
|
|
391
|
+
# A :model row hydrates through child frames, one per document:
|
|
392
|
+
# singular rows have a single pending item.
|
|
393
|
+
def begin_pending(row_index, items, transform, rows, register)
|
|
394
|
+
self.pending_index = row_index
|
|
395
|
+
self.pending_items = items
|
|
396
|
+
self.pending_cursor = 0
|
|
397
|
+
self.pending_built = []
|
|
398
|
+
self.request_transform = transform
|
|
399
|
+
self.request_rows = rows
|
|
400
|
+
self.request_register = register
|
|
401
|
+
end
|
|
402
|
+
|
|
403
|
+
def pending?
|
|
404
|
+
!pending_items.nil?
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
def pending_remaining?
|
|
408
|
+
pending_cursor < pending_items.size
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
# The next child document, or nil for a shape the plan does not
|
|
412
|
+
# cover (a non-Hash item where a model was expected).
|
|
413
|
+
def next_child_document
|
|
414
|
+
item = pending_items[pending_cursor]
|
|
415
|
+
item.is_a?(::Hash) ? item : nil
|
|
416
|
+
end
|
|
417
|
+
|
|
418
|
+
# A finished child joins the row being hydrated; the row's value
|
|
419
|
+
# slot is written once its last child is in.
|
|
420
|
+
def deliver(child)
|
|
421
|
+
pending_built << child
|
|
422
|
+
(self.children ||= []) << child
|
|
423
|
+
self.pending_cursor += 1
|
|
424
|
+
complete_pending! unless pending_remaining?
|
|
425
|
+
end
|
|
426
|
+
|
|
427
|
+
def complete_pending!
|
|
428
|
+
collection = rows[pending_index][1].collection?
|
|
429
|
+
slots[pending_index] = collection ? pending_built : pending_built.first
|
|
430
|
+
clear_pending
|
|
431
|
+
end
|
|
432
|
+
|
|
433
|
+
def clear_pending
|
|
434
|
+
self.pending_index = nil
|
|
435
|
+
self.pending_items = nil
|
|
436
|
+
self.pending_cursor = 0
|
|
437
|
+
self.pending_built = nil
|
|
438
|
+
end
|
|
439
|
+
end
|
|
440
|
+
|
|
341
441
|
# Build values bottom-up, then ONE instance per model: present
|
|
342
442
|
# keys through the casting setters, ABSENT rules through the real
|
|
343
443
|
# per-rule walk (their extractor/defaults/sentinel semantics are
|
|
344
444
|
# the walk's own — reproducing them here would fork them). The
|
|
345
445
|
# per-rule walk is eliminated exactly for the present-key hot
|
|
346
|
-
# path.
|
|
347
|
-
#
|
|
446
|
+
# path. Children hydrate through frames on an explicit stack, not
|
|
447
|
+
# recursion: depth is not bound by the VM stack (#1297). Returns
|
|
448
|
+
# nil (caller falls back) on any shape the plan does not cover,
|
|
449
|
+
# e.g. a non-Hash item where a model was expected.
|
|
348
450
|
def kv_group_build(rows, doc, format, register, options)
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
451
|
+
frames = []
|
|
452
|
+
frame = GroupBuildFrame.new.start(self, rows, doc, format, register,
|
|
453
|
+
options)
|
|
454
|
+
frames << frame
|
|
455
|
+
loop do
|
|
456
|
+
# Each frame is stepped by its own transform, so the walk's
|
|
457
|
+
# private per-rule machinery stays private.
|
|
458
|
+
case frame.transform.kv_frame_step(frame)
|
|
459
|
+
when :child
|
|
460
|
+
# The request rides the frame being stepped; read it before
|
|
461
|
+
# the new frame takes the loop variable.
|
|
462
|
+
child = frames[frames.size] ||= GroupBuildFrame.new
|
|
463
|
+
frame = child.start(frame.request_transform, frame.request_rows,
|
|
464
|
+
frame.request_doc, format,
|
|
465
|
+
frame.request_register, options)
|
|
466
|
+
when :fallback
|
|
467
|
+
return nil
|
|
468
|
+
else
|
|
469
|
+
instance = frame.instance
|
|
470
|
+
frames.pop
|
|
471
|
+
return instance if frames.empty?
|
|
472
|
+
|
|
473
|
+
frame = frames.last
|
|
474
|
+
frame.deliver(instance)
|
|
475
|
+
end
|
|
476
|
+
end
|
|
477
|
+
end
|
|
478
|
+
|
|
479
|
+
# Advances a frame one step: the next child frame it needs
|
|
480
|
+
# (:child), the finished instance (:done), or a shape the plan does
|
|
481
|
+
# not cover (:fallback).
|
|
482
|
+
def kv_frame_step(frame)
|
|
483
|
+
if frame.pending?
|
|
484
|
+
if frame.pending_remaining?
|
|
485
|
+
return request_child(frame)
|
|
486
|
+
end
|
|
487
|
+
|
|
488
|
+
frame.complete_pending!
|
|
489
|
+
end
|
|
490
|
+
rows = frame.rows
|
|
491
|
+
i = frame.index
|
|
492
|
+
while i < rows.size
|
|
493
|
+
row = rows[i]
|
|
494
|
+
rule = row[0]
|
|
495
|
+
kind = row[2]
|
|
363
496
|
if kind == :unmapped
|
|
364
|
-
unmapped = [
|
|
497
|
+
frame.unmapped = [row[3], row[4]]
|
|
365
498
|
i += 1
|
|
366
499
|
next
|
|
367
500
|
end
|
|
@@ -369,9 +502,9 @@ child_mappings)
|
|
|
369
502
|
# One hash pass per row: fetch with a sentinel distinguishes
|
|
370
503
|
# absent keys from present-nil values (both read as nil), so
|
|
371
504
|
# the separate string_or_symbol_key? probe goes away.
|
|
372
|
-
v = Lutaml::Model::Utils.fetch_str_or_sym(doc, rule.name, MISSING)
|
|
505
|
+
v = Lutaml::Model::Utils.fetch_str_or_sym(frame.doc, rule.name, MISSING)
|
|
373
506
|
if v.equal?(MISSING)
|
|
374
|
-
(absent ||= []) << rule
|
|
507
|
+
(frame.absent ||= []) << rule
|
|
375
508
|
i += 1
|
|
376
509
|
next
|
|
377
510
|
end
|
|
@@ -383,89 +516,95 @@ child_mappings)
|
|
|
383
516
|
# parent/root wiring rides the shared children pass. A
|
|
384
517
|
# non-Hash value falls back to the walk, which owns that
|
|
385
518
|
# error.
|
|
386
|
-
return
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
v.each do |child_key, child_value|
|
|
391
|
-
child_hash = {}
|
|
392
|
-
type.child_mappings.each_key do |attr_name|
|
|
393
|
-
child_hash[type.wire_names[attr_name]] =
|
|
394
|
-
extract_compiled_child_value(type.paths[attr_name],
|
|
395
|
-
child_key, child_value)
|
|
396
|
-
end
|
|
397
|
-
child_hash.update(child_value) if keys_only
|
|
398
|
-
built << self.class.data_to_model(type.attr_type,
|
|
399
|
-
child_hash, format, { mappings: type.child_rules })
|
|
400
|
-
end
|
|
401
|
-
values[i] = built
|
|
402
|
-
(children ||= []).concat(built)
|
|
519
|
+
return :fallback unless v.is_a?(::Hash)
|
|
520
|
+
|
|
521
|
+
frame.slots[i] = kv_build_child_map(row[3], v, frame.format)
|
|
522
|
+
(frame.children ||= []).concat(frame.slots[i])
|
|
403
523
|
i += 1
|
|
404
524
|
next
|
|
405
525
|
end
|
|
406
526
|
|
|
407
527
|
if kind == :scalar
|
|
408
|
-
|
|
528
|
+
frame.slots[i] = v
|
|
409
529
|
i += 1
|
|
410
530
|
next
|
|
411
531
|
end
|
|
412
532
|
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
533
|
+
# A present-but-nil collection reaches the per-rule walk,
|
|
534
|
+
# which owns the sentinel interplay for that edge
|
|
535
|
+
# (render_nil :as_empty semantics).
|
|
536
|
+
return :fallback if row[1].collection? && v.nil?
|
|
537
|
+
|
|
538
|
+
items = if row[1].collection?
|
|
539
|
+
v.is_a?(::Array) ? v : [v]
|
|
540
|
+
else
|
|
541
|
+
[v]
|
|
542
|
+
end
|
|
543
|
+
frame.index = i + 1
|
|
544
|
+
frame.begin_pending(i, items,
|
|
545
|
+
self.class.cached_transform(row[3], row[5]),
|
|
546
|
+
row[4], row[5])
|
|
547
|
+
return request_child(frame)
|
|
548
|
+
end
|
|
549
|
+
frame.index = i
|
|
550
|
+
frame.instance = kv_finalize_frame(frame)
|
|
551
|
+
:done
|
|
552
|
+
end
|
|
423
553
|
|
|
424
|
-
|
|
425
|
-
format, child_register,
|
|
426
|
-
options)
|
|
427
|
-
return nil if child.nil?
|
|
554
|
+
private
|
|
428
555
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return nil unless v.is_a?(::Hash)
|
|
556
|
+
# :child when the frame's pending row has a document the plan
|
|
557
|
+
# covers, :fallback otherwise.
|
|
558
|
+
def request_child(frame)
|
|
559
|
+
document = frame.next_child_document
|
|
560
|
+
return :fallback unless document
|
|
435
561
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
return nil if child.nil?
|
|
562
|
+
frame.request_doc = document
|
|
563
|
+
:child
|
|
564
|
+
end
|
|
440
565
|
|
|
441
|
-
|
|
442
|
-
|
|
566
|
+
def kv_build_child_map(plan, value, format)
|
|
567
|
+
built = []
|
|
568
|
+
keys_only = plan.keys_only && value.values.all?(::Hash)
|
|
569
|
+
value.each do |child_key, child_value|
|
|
570
|
+
child_hash = {}
|
|
571
|
+
plan.child_mappings.each_key do |attr_name|
|
|
572
|
+
child_hash[plan.wire_names[attr_name]] =
|
|
573
|
+
extract_compiled_child_value(plan.paths[attr_name],
|
|
574
|
+
child_key, child_value)
|
|
443
575
|
end
|
|
444
|
-
|
|
576
|
+
child_hash.update(child_value) if keys_only
|
|
577
|
+
built << self.class.data_to_model(plan.attr_type, child_hash,
|
|
578
|
+
format, { mappings: plan.child_rules })
|
|
445
579
|
end
|
|
446
|
-
|
|
580
|
+
built
|
|
581
|
+
end
|
|
582
|
+
|
|
583
|
+
def kv_finalize_frame(frame)
|
|
584
|
+
instance = model_class.allocate_for_walk(frame.register)
|
|
585
|
+
values = frame.slots
|
|
447
586
|
i = 0
|
|
448
587
|
# Index access, not block-parameter splat: `*_rest` re-sliced a
|
|
449
588
|
# fresh Array per row per instance (the walk's largest our-side
|
|
450
589
|
# allocation line on the synthetic KV corpus).
|
|
451
|
-
rows.each do |row|
|
|
590
|
+
frame.rows.each do |row|
|
|
452
591
|
v = values[i]
|
|
453
592
|
i += 1
|
|
454
593
|
next if v.equal?(MISSING) || row[2] == :unmapped
|
|
455
594
|
|
|
456
595
|
instance.public_send(row[0].kv_setter, v)
|
|
457
596
|
end
|
|
458
|
-
absent&.each do |rule|
|
|
459
|
-
process_mapping_rule(doc, instance, format, rule, options, nil)
|
|
597
|
+
frame.absent&.each do |rule|
|
|
598
|
+
process_mapping_rule(frame.doc, instance, frame.format, rule, frame.options, nil)
|
|
460
599
|
end
|
|
461
|
-
children&.each do |child|
|
|
600
|
+
frame.children&.each do |child|
|
|
462
601
|
child.lutaml_parent = instance
|
|
463
602
|
child.lutaml_root ||= instance.lutaml_root || instance
|
|
464
603
|
end
|
|
465
|
-
if unmapped
|
|
466
|
-
target, claimed = unmapped
|
|
604
|
+
if frame.unmapped
|
|
605
|
+
target, claimed = frame.unmapped
|
|
467
606
|
extras = nil
|
|
468
|
-
doc.each do |key, value|
|
|
607
|
+
frame.doc.each do |key, value|
|
|
469
608
|
next if claimed.key?(key.to_s)
|
|
470
609
|
|
|
471
610
|
(extras ||= {})[key] = value
|
|
@@ -479,16 +618,6 @@ child_hash, format, { mappings: type.child_rules })
|
|
|
479
618
|
instance
|
|
480
619
|
end
|
|
481
620
|
|
|
482
|
-
def self.kv_group_instance(model_class, rows, doc, format, register,
|
|
483
|
-
options)
|
|
484
|
-
# cached_transform is per (class, register); format rides the
|
|
485
|
-
# call, not the cache.
|
|
486
|
-
cached_transform(model_class, register)
|
|
487
|
-
.kv_group_build(rows, doc, format, register, options)
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
private
|
|
491
|
-
|
|
492
621
|
def process_rule!(instance, rule, hash, format, _mappings, options)
|
|
493
622
|
return handle_delegate(instance, rule, hash, format) if rule.delegate
|
|
494
623
|
|
|
@@ -1709,6 +1709,10 @@ instance_object = nil)
|
|
|
1709
1709
|
def valid_polymorphic_type?(value)
|
|
1710
1710
|
return value.is_a?(type) unless has_polymorphic_list?
|
|
1711
1711
|
|
|
1712
|
+
# A list of String names alone restricts nothing beyond the
|
|
1713
|
+
# declared base: the names are never resolved (#1306).
|
|
1714
|
+
return value.is_a?(type) if polymorphic_names_only?
|
|
1715
|
+
|
|
1712
1716
|
return true if polymorphic_scalar_member?(value)
|
|
1713
1717
|
return false unless value.is_a?(Serialize)
|
|
1714
1718
|
|
|
@@ -1719,12 +1723,15 @@ instance_object = nil)
|
|
|
1719
1723
|
|
|
1720
1724
|
# Definition-time contract for the polymorphic list: an entry that can
|
|
1721
1725
|
# never match anything — a Symbol other than :array — fails the
|
|
1722
|
-
# declaration instead of surfacing at serialization (#1292).
|
|
1726
|
+
# declaration instead of surfacing at serialization (#1292). A String
|
|
1727
|
+
# is the lazy type-name form a String attribute type takes; its class
|
|
1728
|
+
# may not be loaded at declaration time, so it is accepted here and
|
|
1729
|
+
# the list never resolves it (#1306).
|
|
1723
1730
|
def validate_polymorphic_entries!(entries)
|
|
1724
1731
|
return unless entries.is_a?(Array)
|
|
1725
1732
|
|
|
1726
1733
|
entries.each do |entry|
|
|
1727
|
-
next if entry.is_a?(Class) || entry == :array
|
|
1734
|
+
next if entry.is_a?(Class) || entry.is_a?(String) || entry == :array
|
|
1728
1735
|
|
|
1729
1736
|
raise ArgumentError,
|
|
1730
1737
|
"polymorphic entry #{entry.inspect} is not a type: use a " \
|
|
@@ -1735,6 +1742,11 @@ instance_object = nil)
|
|
|
1735
1742
|
def has_polymorphic_list?
|
|
1736
1743
|
options[:polymorphic]&.is_a?(Array)
|
|
1737
1744
|
end
|
|
1745
|
+
|
|
1746
|
+
def polymorphic_names_only?
|
|
1747
|
+
list = options[:polymorphic]
|
|
1748
|
+
list.any?(String) && list.none?(Class)
|
|
1749
|
+
end
|
|
1738
1750
|
end
|
|
1739
1751
|
end
|
|
1740
1752
|
end
|
|
@@ -206,14 +206,13 @@ module Lutaml
|
|
|
206
206
|
# yields each resolved element-order item with its owning schema.
|
|
207
207
|
def each_schema_item(schemas, &dispatch)
|
|
208
208
|
schemas.each do |schema|
|
|
209
|
-
#
|
|
210
|
-
#
|
|
211
|
-
#
|
|
212
|
-
#
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
end
|
|
209
|
+
# An override's composed view is reachable from its entry
|
|
210
|
+
# (the override collection holds the declarations only);
|
|
211
|
+
# the view carries the referenced document's walkable
|
|
212
|
+
# element order with the replacements substituted.
|
|
213
|
+
Array(schema.override).each do |entry|
|
|
214
|
+
view = entry.composed
|
|
215
|
+
each_schema_item([view], &dispatch) if view
|
|
217
216
|
end
|
|
218
217
|
if schema.include&.any?
|
|
219
218
|
each_schema_item(schema.include,
|