lutaml-model 0.8.148 → 0.8.150

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a830ec6a143525a0d59b70b642ffa232553eb7aadb9d1b6a7cd740a1cfcad6cb
4
- data.tar.gz: 565167c64a78c785ff6f6742bce3ee5c56083022bd9c37746af983cace306262
3
+ metadata.gz: d607b4c544596f3b22830d7d5636a86415609ba1589e6749ce22f6d5ed7bc800
4
+ data.tar.gz: 9eb79acc5964cab4c5c1930c30579c2fd7cb5c5e29720d131208d4ce74667e24
5
5
  SHA512:
6
- metadata.gz: e26f1bec70e96e4311140e345cd7cb15e048b71fe37df05d96bbe8cf319b959bba4e6a6073ac61767e4a6c8a94c7a3e14c5decab75412718bb73cf7d7fee6e1a
7
- data.tar.gz: a2c55f36c898966db5499b0485702a50749bef098ff3f07e8e4ee90caab1d2c112294adc59da7a6dac486d256679f4f27a426b8384e35932a3228998b27e21f5
6
+ metadata.gz: 04e478685e1c6c4a30a9475ba31b39fc2353858f8929c7725101da530648628c58985c0e086f664a06c75fc117fd521b7ad6e63b547d5bbdc571eb8113810275
7
+ data.tar.gz: f3dee9b947b17ea7aceda5c4178a89aeb2d88c43a0007fb56adadee103e1f9c2b6ce6cf5139870fb42bdc218eb1b9bd4c92750c54bbab4cd0e94549169f554f0
@@ -566,8 +566,26 @@ module Lutaml
566
566
  # defaults would otherwise count as set and a render_default:
567
567
  # false element would be written back out.
568
568
  if constructs_through_initialize?
569
- instance = new(lutaml_register: register_id)
570
- instance.init_deserialization_state(register_id)
569
+ # (#1059) Run the custom initialize against COMPILED
570
+ # constructor-equivalent state — the walk seed (defaults
571
+ # resolved, non-defaulted attributes nil), not the
572
+ # deserialization seed: constructor bodies branch on
573
+ # truthiness and is_a? checks of plain state, and an
574
+ # UninitializedClass sentinel is truthy, so seeding
575
+ # sentinels here would misfire every convenience-conversion
576
+ # branch (uniword's convert_flat_attributes! constructed
577
+ # wrapper objects per node). The generic attribute walk is
578
+ # still stood down for the run — it would only re-materialize
579
+ # the same defaults the seed already wrote — and #922's
580
+ # finalize then resets attribute state to the deserialization
581
+ # markers, so constructor-seeded defaults do not count as
582
+ # set, exactly as before.
583
+ instance = allocate
584
+ instance.init_walk_state(register_id)
585
+ instance.lutaml_constructor_seeded = true
586
+ instance.send(:initialize)
587
+ instance.lutaml_constructor_seeded = nil
588
+ instance.finalize_deserialization(register_id)
571
589
  return instance
572
590
  end
573
591
  instance = allocate
@@ -595,11 +613,12 @@ module Lutaml
595
613
  register_id = instance.lutaml_register
596
614
  attrs_by = attributes(register_id)
597
615
  writers = instantiate_writers(register_id)
616
+ raw_readers = instantiate_raw_readers(register_id)
598
617
  given = 0
599
618
  # Memoized pair array: Hash#each mints a [name, attr] pair
600
619
  # per attribute per instance (~5 allocs/instance on
601
620
  # hydration-heavy corpora); Array#each reuses its elements.
602
- instantiate_attr_pairs(register_id).each do |name, attr|
621
+ instantiate_attr_pairs(register_id).each do |name, attr, str_name|
603
622
  next if attr.derived?
604
623
 
605
624
  # Symbol keys hit directly (native-extension callers);
@@ -607,7 +626,7 @@ module Lutaml
607
626
  key = if attrs.key?(name)
608
627
  given += 1
609
628
  name
610
- elsif (str_name = name.to_s) && attrs.key?(str_name)
629
+ elsif attrs.key?(str_name)
611
630
  given += 1
612
631
  str_name
613
632
  end
@@ -629,7 +648,7 @@ module Lutaml
629
648
  # only then is the default seeded. The writer's own
630
649
  # value_set_for (inside the compiled writer) already
631
650
  # marked it set, so it renders.
632
- raw = instance.public_send(:"__lutaml_raw_#{name}")
651
+ raw = instance.public_send(raw_readers[name])
633
652
  unset = raw.nil? ||
634
653
  raw.equal?(Lutaml::Model::UninitializedClass.instance) ||
635
654
  raw.equal?(Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION)
@@ -670,7 +689,24 @@ module Lutaml
670
689
  # pair array disappears (see the instantiate comment).
671
690
  def instantiate_attr_pairs(register_id = nil)
672
691
  (@instantiate_attr_pairs ||= {})[register_id] ||=
673
- attributes(register_id).to_a.freeze
692
+ attributes(register_id).map do |name, attr|
693
+ # The string name is precomputed beside the symbol: the
694
+ # absent-key fallback (string-keyed callers, from_hash)
695
+ # would otherwise mint `name.to_s` per attribute per
696
+ # instance — one fresh string per absent attribute.
697
+ [name, attr, name.to_s]
698
+ end.freeze
699
+ end
700
+
701
+ # Raw-state reader names, precomputed once per (class, register):
702
+ # instantiating interpolates the reader symbol per absent
703
+ # attribute per instance otherwise — a fresh string + symbol
704
+ # lookup for state that is identical for every instance.
705
+ def instantiate_raw_readers(register_id = nil)
706
+ (@instantiate_raw_readers ||= {})[register_id] ||=
707
+ attributes(register_id).to_h do |name, _|
708
+ [name, :"__lutaml_raw_#{name}"]
709
+ end.freeze
674
710
  end
675
711
 
676
712
  # Define register-specific attribute methods on the class itself.
@@ -154,7 +154,26 @@ module Lutaml
154
154
 
155
155
  attr_accessor :lutaml_register, :lutaml_parent, :lutaml_root
156
156
 
157
+ # Internal deserialization state (#1059): the XML constructor path
158
+ # seeds constructor-equivalent compiled state, runs the user
159
+ # initialize, and only then resets attribute state to the
160
+ # deserialization markers (#922). While the flag is set,
161
+ # #initialize stands down — its generic attribute walk would only
162
+ # re-materialize defaults that the post-run reset discards.
163
+ attr_accessor :lutaml_constructor_seeded
164
+
157
165
  def initialize(attrs = {}, options = {})
166
+ if lutaml_constructor_seeded
167
+ # The deserialization constructor seeded constructor-equivalent
168
+ # compiled state (defaults resolved, non-defaulted nil) and
169
+ # resets attribute state after this initialize returns; the
170
+ # generic attribute walk here would only materialize defaults
171
+ # that the reset then discards (#922). This IS the custom
172
+ # initialize's super call — the body above us has already run
173
+ # against that state.
174
+ return
175
+ end
176
+
158
177
  @using_default = {}
159
178
  @lutaml_register = extract_register_id(attrs, options)
160
179
  return unless self.class.attributes(@lutaml_register)
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.8.148"
5
+ VERSION = "0.8.150"
6
6
  end
7
7
  end
@@ -1460,11 +1460,22 @@ module Lutaml
1460
1460
  # Raw xsi:schemaLocation capture must stay out of the way, or the
1461
1461
  # writer re-emits the value beside the mapped attribute (#1042).
1462
1462
  def schema_location_mapped?(register_id = nil)
1463
- mapping_attributes_hash(register_id).each_value.any? do |rule_or_array|
1463
+ # Memoized per register against the mapping's rule-records
1464
+ # version: the walk re-asks per parse, and the un-memoized form
1465
+ # allocated a merged attributes hash plus a name string per rule
1466
+ # per ask.
1467
+ version = rule_records_version.to_i
1468
+ cache = (@schema_location_mapped ||= {})
1469
+ cached = cache[register_id]
1470
+ return cached[:value] if cached && cached[:version] == version
1471
+
1472
+ value = mapping_attributes_hash(register_id).each_value.any? do |rule_or_array|
1464
1473
  Array(rule_or_array).any? do |rule|
1465
1474
  rule.name.to_s == "schemaLocation"
1466
1475
  end
1467
1476
  end
1477
+ cache[register_id] = { version: version, value: value }
1478
+ value
1468
1479
  end
1469
1480
 
1470
1481
  # Raw hash access for inheritance and deep_dup operations.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml-model
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.148
4
+ version: 0.8.150
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-10-30 00:00:00.000000000 Z
11
+ date: 2026-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64