Module: Axn::Core::ContractForSubfields::ClassMethods

Defined in:
lib/axn/core/contract_for_subfields.rb

Instance Method Summary collapse

Instance Method Details

#_resolved_subfieldsObject

The class's canonical resolved-subfield structure (PRO-2883), built lazily and cached on the class. Cache validity is decided by IDENTITY of the two config arrays: both are copy-on-write class_attributes mutated exclusively via +=, so any declaration — on this class or a subclass — mints new arrays and the stale entry misses on equal?. That gives invalidation with no explicit hooks (a future mutation site is auto-covered), no nil-memoization footgun (validity never consults the value), and free copy-on-write subclass inheritance (an undeclaring subclass reads the superclass's arrays and builds an identical artifact once). The artifact is deep-frozen and published in a single ivar write, so a first-call race between threads is benign.



458
459
460
461
462
463
464
465
466
467
# File 'lib/axn/core/contract_for_subfields.rb', line 458

def _resolved_subfields
  fields = internal_field_configs
  subfields = subfield_configs
  cached = @_axn_resolved_subfields
  return cached.value if cached && cached.fields.equal?(fields) && cached.subfields.equal?(subfields)

  value = Axn::Internal::ResolvedSubfields.build(fields, subfields)
  @_axn_resolved_subfields = ResolvedSubfieldsCacheEntry.new(fields:, subfields:, value:)
  value
end