lutaml-model 0.8.201 → 0.8.202

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 (144) hide show
  1. checksums.yaml +4 -4
  2. data/.github/scripts/test_installed_gem.rb +1 -13
  3. data/.github/workflows/downstream-performance.yml +1 -22
  4. data/.github/workflows/performance.yml +1 -33
  5. data/.github/workflows/rake.yml +2 -6
  6. data/.rubocop.yml +0 -10
  7. data/.rubocop_todo.yml +0 -4
  8. data/Gemfile +0 -23
  9. data/README.adoc +25 -86
  10. data/Rakefile +2 -167
  11. data/docs/_guides/advanced-mapping.adoc +6 -6
  12. data/docs/_guides/character-encoding.adoc +0 -3
  13. data/docs/_guides/gem-integration.adoc +1 -1
  14. data/docs/_guides/index.adoc +0 -4
  15. data/docs/_guides/xml/type-namespaces.adoc +1 -1
  16. data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
  17. data/docs/_guides/xml-namespaces.adoc +2 -3
  18. data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
  19. data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
  20. data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
  21. data/docs/_pages/comparison-with-shale.adoc +1 -1
  22. data/docs/_pages/configuration.adoc +6 -40
  23. data/docs/_pages/index.adoc +0 -1
  24. data/docs/_pages/serialization_adapters.adoc +4 -16
  25. data/docs/_references/architecture.adoc +1 -1
  26. data/docs/_references/lutaml-namespace-planning.md +1 -1
  27. data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
  28. data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
  29. data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
  30. data/docs/architecture.md +7 -11
  31. data/docs/conversion_caching.adoc +1 -1
  32. data/docs/index.adoc +0 -1
  33. data/docs/key_value_data_model.adoc +1 -1
  34. data/docs/namespace-management.adoc +4 -10
  35. data/lib/lutaml/json/format.rb +0 -1
  36. data/lib/lutaml/json/generator_options.rb +0 -1
  37. data/lib/lutaml/key_value/transform.rb +9 -16
  38. data/lib/lutaml/lml/document_builder.rb +2 -2
  39. data/lib/lutaml/lml/entity_types.rb +2 -2
  40. data/lib/lutaml/model/adapter_resolver.rb +5 -15
  41. data/lib/lutaml/model/cached_type_resolver.rb +1 -7
  42. data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
  43. data/lib/lutaml/model/global_context.rb +3 -5
  44. data/lib/lutaml/model/instrumentation.rb +0 -3
  45. data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
  46. data/lib/lutaml/model/register.rb +20 -31
  47. data/lib/lutaml/model/runtime_compatibility.rb +0 -92
  48. data/lib/lutaml/model/schema/class_loader.rb +2 -4
  49. data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
  50. data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
  51. data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
  52. data/lib/lutaml/model/serialize/model_import.rb +0 -5
  53. data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
  54. data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
  55. data/lib/lutaml/model/store.rb +10 -17
  56. data/lib/lutaml/model/toml.rb +0 -2
  57. data/lib/lutaml/model/transformation_registry.rb +3 -7
  58. data/lib/lutaml/model/version.rb +1 -1
  59. data/lib/lutaml/model.rb +3 -19
  60. data/lib/lutaml/toml/format.rb +4 -8
  61. data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
  62. data/lib/lutaml/xml/adapter.rb +0 -4
  63. data/lib/lutaml/xml/adapter_loader.rb +1 -6
  64. data/lib/lutaml/xml/builder/base.rb +0 -3
  65. data/lib/lutaml/xml/builder.rb +0 -8
  66. data/lib/lutaml/xml/data_model.rb +1 -1
  67. data/lib/lutaml/xml/doctype_extractor.rb +3 -3
  68. data/lib/lutaml/xml/format.rb +22 -74
  69. data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
  70. data/lib/lutaml/xml/model_transform.rb +14 -24
  71. data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
  72. data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
  73. data/lib/lutaml/xml/schema/builder.rb +6 -9
  74. data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
  75. data/lib/lutaml/xml/xml_element.rb +3 -2
  76. data/lib/lutaml/xml/xsd_validator.rb +4 -11
  77. data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
  78. data/lib/lutaml/yamls/adapter_loader.rb +1 -5
  79. data/lib/tasks/performance_comparator.rb +1 -1
  80. data/lutaml-model.gemspec +3 -8
  81. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
  82. data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
  83. data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
  84. data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
  85. data/spec/lutaml/model/cdata_spec.rb +2 -15
  86. data/spec/lutaml/model/encoding_spec.rb +0 -9
  87. data/spec/lutaml/model/except_spec.rb +0 -7
  88. data/spec/lutaml/model/json_spec.rb +0 -14
  89. data/spec/lutaml/model/mixed_content_spec.rb +6 -46
  90. data/spec/lutaml/model/ordered_content_spec.rb +0 -7
  91. data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
  92. data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
  93. data/spec/lutaml/model/serializable_spec.rb +0 -2
  94. data/spec/lutaml/model/toml_spec.rb +0 -23
  95. data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
  96. data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
  97. data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
  98. data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
  99. data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
  100. data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
  101. data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
  102. data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
  103. data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
  104. data/spec/lutaml/xml/mapping_spec.rb +8 -15
  105. data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
  106. data/spec/lutaml/xml/namespace_spec.rb +0 -13
  107. data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
  108. data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
  109. data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
  110. data/spec/lutaml/xml/xml_spec.rb +2 -88
  111. data/spec/spec_helper.rb +5 -24
  112. data/spec/support/test_adapter_config.rb +6 -6
  113. metadata +1 -32
  114. data/.github/workflows/js-pr-check.yml +0 -106
  115. data/.github/workflows/js-sync.yml +0 -55
  116. data/.github/workflows/opal.yml +0 -65
  117. data/.gitmodules +0 -6
  118. data/.rspec-opal +0 -5
  119. data/docs/_guides/opal.adoc +0 -232
  120. data/lib/compat/opal/generate_boot.rb +0 -137
  121. data/lib/compat/opal/js_bundle_entry.rb +0 -42
  122. data/lib/compat/opal/lutaml_model_boot.rb +0 -638
  123. data/lib/compat/opal/monitor.rb +0 -31
  124. data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
  125. data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
  126. data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
  127. data/lib/compat/opal/moxml_boot.rb +0 -68
  128. data/lib/compat/opal/objectspace_shim.rb +0 -23
  129. data/lib/compat/opal/rexml/namespace.rb +0 -59
  130. data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
  131. data/lib/compat/opal/rexml/source.rb +0 -214
  132. data/lib/compat/opal/rexml/text.rb +0 -426
  133. data/lib/compat/opal/rexml/xmltokens.rb +0 -45
  134. data/lib/compat/opal/rexml_compat.rb +0 -85
  135. data/lib/compat/opal/yaml_compat.rb +0 -32
  136. data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
  137. data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
  138. data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
  139. data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
  140. data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
  141. data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
  142. data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
  143. data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
  144. data/spec/support/opal.rb +0 -9
@@ -32,16 +32,13 @@ module Lutaml
32
32
  # Adapters on the deprecation path. moxml is the only supported
33
33
  # XML facade going forward, and its default engine (Nokogiri,
34
34
  # with the leptris native engine preferred when present) is the
35
- # supported lane; the pure-Ruby REXML and Oga engines remain
36
- # loadable but select for the last time in the 0.8 line.
35
+ # supported lane; the pure-Ruby REXML engine remains loadable
36
+ # but selects for the last time in the 0.8 line.
37
37
  DEPRECATED_ADAPTERS = {
38
38
  %i[xml rexml] => "the REXML engine is deprecated; moxml's " \
39
39
  "default engine (Nokogiri, or the leptris " \
40
40
  "native engine when present) is the supported " \
41
41
  "XML lane",
42
- %i[xml oga] => "the Oga engine is deprecated; moxml's default " \
43
- "engine (Nokogiri, or the leptris native engine " \
44
- "when present) is the supported XML lane",
45
42
  }.freeze
46
43
 
47
44
  # --- Resolution ---
@@ -294,12 +291,8 @@ module Lutaml
294
291
  end
295
292
 
296
293
  # Default key-value adapter loading
297
- adapter_path = if Lutaml::Model.opal?
298
- "lutaml/key_value/adapter/#{adapter}/#{type}"
299
- else
300
- File.join(File.dirname(__FILE__), "../key_value/adapter",
301
- adapter, type)
302
- end
294
+ adapter_path = File.join(File.dirname(__FILE__), "../key_value/adapter",
295
+ adapter, type)
303
296
  require adapter_path
304
297
  rescue LoadError => e
305
298
  # Chain the cause so a missing engine gem is named, not masked.
@@ -452,7 +445,6 @@ module Lutaml
452
445
  # instead of a clean standard-lane parse (#978).
453
446
  def detect_yeptris_kv_adapter(format)
454
447
  default = metadata.dig(format, :default)
455
- return default if Lutaml::Model.opal?
456
448
  return default unless Utils.safe_load("yeptris", :Yeptris)
457
449
 
458
450
  load_adapter(format, :yeptris).available? ? :yeptris : default
@@ -461,7 +453,7 @@ module Lutaml
461
453
  # Detect available XML adapter.
462
454
  #
463
455
  # Delegates to moxml which is the authority on XML adapter
464
- # availability and platform constraints (Opal, MRI, etc.).
456
+ # availability and platform constraints.
465
457
  #
466
458
  # @return [Symbol] adapter type name
467
459
  def detect_xml_adapter
@@ -472,8 +464,6 @@ module Lutaml
472
464
  #
473
465
  # @return [Symbol, nil] :teptris, :tomlib, :toml_rb, or nil
474
466
  def detect_toml_adapter
475
- return nil if Lutaml::Model.opal?
476
-
477
467
  # teptris 0.2.12+ parses ~3x and dumps ~8x faster than
478
468
  # tomlib and ships prebuilts for every platform (mingw-ucrt
479
469
  # restored in 0.2.4+) — native TOML on Windows retires the
@@ -29,18 +29,12 @@ module Lutaml
29
29
  self,
30
30
  ConcurrentMapCache: "#{__dir__}/cached_type_resolver/concurrent_map_cache",
31
31
  )
32
- autoload :MutexHashCache,
33
- "#{__dir__}/cached_type_resolver/mutex_hash_cache"
34
32
 
35
33
  # @return [Object] The delegate resolver (typically TypeResolver)
36
34
  attr_reader :delegate, :cache_backend
37
35
 
38
36
  def self.default_cache_backend
39
- if Lutaml::Model.opal?
40
- MutexHashCache.new
41
- else
42
- ConcurrentMapCache.new
43
- end
37
+ ConcurrentMapCache.new
44
38
  end
45
39
 
46
40
  # Create a new CachedTypeResolver.
@@ -3,7 +3,7 @@ module Lutaml
3
3
  class UnknownAdapterTypeError < Error
4
4
  # Available adapters by format
5
5
  AVAILABLE_ADAPTERS = {
6
- xml: %w[nokogiri ox oga rexml leptris],
6
+ xml: %w[nokogiri ox rexml leptris],
7
7
  json: %w[standard multi_json oj yeptris],
8
8
  yaml: %w[standard yeptris],
9
9
  toml: %w[teptris tomlib toml_rb],
@@ -344,11 +344,9 @@ context_id = nil)
344
344
  end
345
345
 
346
346
  class << self
347
- # Block form: avoids Opal's runtime string parsing requirement
348
- # (MRI's class_eval(string) needs `require 'opal-parser'` at
349
- # runtime under Opal, which isn't bundled). Closures are
350
- # allocated once at file load, not per call, so the perf cost
351
- # over the previous string form is negligible.
347
+ # Block form (no String class_eval). Closures are allocated
348
+ # once at file load, not per call, so the perf cost over a
349
+ # string form is negligible.
352
350
 
353
351
  class_eval do
354
352
  def registry
@@ -155,8 +155,6 @@ module Lutaml
155
155
  #
156
156
  # @return [Float] the current monotonic time in seconds
157
157
  def monotonic_time
158
- return Time.now.to_f if Lutaml::Model.opal?
159
-
160
158
  Process.clock_gettime(Process::CLOCK_MONOTONIC)
161
159
  end
162
160
 
@@ -164,7 +162,6 @@ module Lutaml
164
162
  #
165
163
  # @return [Integer, nil] memory in bytes, or nil if not available
166
164
  def memory_usage
167
- return nil if Lutaml::Model.opal?
168
165
  return nil unless defined?(GC)
169
166
 
170
167
  GC.start if RUBY_VERSION >= "2.7"
@@ -487,16 +487,12 @@ context = nil, pre_cast: false)
487
487
  # that class's attribute, or nil when only a casting writer
488
488
  # exists (custom writers, reflective names, enum shorthands).
489
489
  # Class-level because mapping rules may be frozen (see the
490
- # name-string note above TRANSFORM_DISPATCH). Concurrent::Map
491
- # under threaded MRI, plain identity Hash under Opal — writes are
492
- # idempotent (the same verdict is recomputed).
493
- PARSED_ASSIGN_WRITERS = if Lutaml::Model.opal?
494
- {}.compare_by_identity
495
- else
496
- Lutaml::Model::RuntimeCompatibility
497
- .require_native("concurrent")
498
- Concurrent::Map.new
499
- end
490
+ # name-string note above TRANSFORM_DISPATCH). Concurrent::Map —
491
+ # writes are idempotent (the same verdict is recomputed).
492
+ PARSED_ASSIGN_WRITERS = begin
493
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
494
+ Concurrent::Map.new
495
+ end
500
496
 
501
497
  def self.transform_dispatch(rule, attr)
502
498
  per_attr = TRANSFORM_DISPATCH[rule]
@@ -52,13 +52,10 @@ module Lutaml
52
52
  # require is still in flight makes concurrent-ruby's optional
53
53
  # native-extension requires raise inside RubyGems' unresolved-tree
54
54
  # resolution, which walks every installed gem on gem-heavy machines.
55
- RESOLVE_CACHE = if Lutaml::Model.opal?
56
- {}
57
- else
58
- Lutaml::Model::RuntimeCompatibility
59
- .require_native("concurrent")
60
- Concurrent::Map.new
61
- end
55
+ RESOLVE_CACHE = begin
56
+ Lutaml::Model::RuntimeCompatibility.require_native("concurrent")
57
+ Concurrent::Map.new
58
+ end
62
59
 
63
60
  # Clear the resolve_for_child cache.
64
61
  # Called from add_fallback and GlobalContext.clear_caches.
@@ -86,30 +83,22 @@ module Lutaml
86
83
  # @param parent_register [Symbol, String, nil] The parent's register/context ID
87
84
  # @return [Symbol, nil] The register ID to use for the child
88
85
  def self.resolve_for_child(child_class, parent_register)
89
- if Lutaml::Model.opal?
90
- per_class = RESOLVE_CACHE[child_class] # rubocop:todo Style/IdenticalConditionalBranches
91
- return per_class[parent_register] if per_class&.key?(parent_register)
92
-
93
- (RESOLVE_CACHE[child_class] ||= {})[parent_register] =
94
- _resolve_for_child_uncached(child_class, parent_register)
95
- else
96
- # Read-first: Concurrent::Map#compute_if_absent takes the mutex
97
- # on EVERY call, hits included — 1.35 M synchronized blocks per
98
- # ISO-13849 parse for answers that never change. The plain #[]
99
- # read is lock-free; nil is a valid cached answer, hence key?.
100
- # Nested maps: class → register → result. Every hop keys on a
101
- # stable object (Class / Symbol), so the hot lookup allocates
102
- # nothing — the flat [object_id, register] array key cost one
103
- # Array per call, six per parsed element.
104
- per_class = RESOLVE_CACHE[child_class] # rubocop:todo Style/IdenticalConditionalBranches
105
- return per_class[parent_register] if per_class&.key?(parent_register)
106
-
107
- per_class = RESOLVE_CACHE.compute_if_absent(child_class) do
108
- Concurrent::Map.new
109
- end
110
- per_class.compute_if_absent(parent_register) do
111
- _resolve_for_child_uncached(child_class, parent_register)
112
- end
86
+ # Read-first: Concurrent::Map#compute_if_absent takes the mutex
87
+ # on EVERY call, hits included — 1.35 M synchronized blocks per
88
+ # ISO-13849 parse for answers that never change. The plain #[]
89
+ # read is lock-free; nil is a valid cached answer, hence key?.
90
+ # Nested maps: class → register → result. Every hop keys on a
91
+ # stable object (Class / Symbol), so the hot lookup allocates
92
+ # nothing — the flat [object_id, register] array key cost one
93
+ # Array per call, six per parsed element.
94
+ per_class = RESOLVE_CACHE[child_class]
95
+ return per_class[parent_register] if per_class&.key?(parent_register)
96
+
97
+ per_class = RESOLVE_CACHE.compute_if_absent(child_class) do
98
+ Concurrent::Map.new
99
+ end
100
+ per_class.compute_if_absent(parent_register) do
101
+ _resolve_for_child_uncached(child_class, parent_register)
113
102
  end
114
103
  end
115
104
 
@@ -3,38 +3,22 @@
3
3
  module Lutaml
4
4
  module Model
5
5
  module RuntimeCompatibility
6
- def self.opal?
7
- return @opal if defined?(@opal)
8
-
9
- @opal = RUBY_ENGINE == "opal"
10
- end
11
-
12
6
  def self.windows?
13
7
  defined?(Gem) &&
14
8
  Gem.win_platform?
15
9
  end
16
10
 
17
- def self.native?
18
- !opal?
19
- end
20
-
21
11
  def self.autoload_native(namespace, constant_paths)
22
- return unless native?
23
-
24
12
  constant_paths.each do |constant_name, path|
25
13
  namespace.autoload(constant_name, path)
26
14
  end
27
15
  end
28
16
 
29
17
  def self.require_native(*paths)
30
- return unless native?
31
-
32
18
  paths.each { |path| require path }
33
19
  end
34
20
 
35
21
  def self.define_native_aliases(namespace, constant_targets)
36
- return unless native?
37
-
38
22
  constant_targets.each do |constant_name, target_name|
39
23
  namespace.const_set(constant_name, constantize(target_name))
40
24
  end
@@ -66,79 +50,3 @@ module Lutaml
66
50
  end
67
51
  end
68
52
  end
69
-
70
- if Lutaml::Model::RuntimeCompatibility.opal?
71
- unless defined?(Mutex)
72
- class ::Mutex
73
- def synchronize
74
- yield
75
- end
76
- end
77
- end
78
-
79
- unless defined?(ConditionVariable)
80
- class ::ConditionVariable
81
- def wait(*); end
82
-
83
- def broadcast; end
84
- end
85
- end
86
-
87
- unless defined?(Thread)
88
- class ::Thread
89
- def self.current
90
- @current ||= {}
91
- end
92
- end
93
- end
94
-
95
- # Opal has no `weakref` stdlib. Store uses WeakRef to let go of
96
- # registered instances automatically once they go out of scope.
97
- # Under Opal (browser JS GC) we substitute a strong reference —
98
- # correct behavior, weaker memory profile, no API surface change.
99
- unless defined?(WeakRef)
100
- class ::WeakRef
101
- class RefError < ::StandardError; end
102
-
103
- def initialize(obj)
104
- @__target__ = obj
105
- end
106
-
107
- def __getobj__
108
- @__target__
109
- end
110
-
111
- def weakref_alive?
112
- true
113
- end
114
-
115
- # Minimal method_missing so the WeakRef quacks like its target
116
- # for the Store's index lookups.
117
- def method_missing(name, ...)
118
- @__target__.public_send(name, ...)
119
- end
120
-
121
- def respond_to_missing?(name, include_private = false)
122
- @__target__.respond_to?(name, include_private)
123
- end
124
- end
125
- end
126
-
127
- # Opal's Module#prepend raises "Prepending a module multiple times
128
- # is not supported" when a module is already in the target's ancestor
129
- # chain. MRI's prepend is idempotent in that case (no-op, no error).
130
- #
131
- # Our top-level lib files (lib/lutaml/model.rb, lib/lutaml/xml.rb)
132
- # can be re-evaluated under Opal's eager loader, which would trigger
133
- # the raise on the second pass. Align Opal with MRI by making prepend
134
- # a no-op when the module is already present.
135
- class ::Module
136
- unless method_defined?(:__lm_original_prepend__)
137
- alias_method :__lm_original_prepend__, :prepend
138
-
139
- def prepend(mod)
140
- __lm_original_prepend__(mod) unless self <= mod
141
- end
142
- end
143
- end
144
- end
@@ -1,9 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- unless RUBY_ENGINE == "opal"
4
- require "fileutils"
5
- require "tmpdir"
6
- end
3
+ require "fileutils"
4
+ require "tmpdir"
7
5
 
8
6
  module Lutaml
9
7
  module Model
@@ -149,9 +149,8 @@ module Lutaml
149
149
  values.public_send(:"#{method}_by") { |v| comparable_bound(v) }
150
150
  end
151
151
 
152
- # Lazy, guarded require (mirrors Type::Decimal) so this Opal-booted
153
- # file has no load-time bigdecimal dependency; the XSD compiler is a
154
- # native-only path, so this only runs under MRI.
152
+ # Lazy, guarded require (mirrors Type::Decimal) so this file
153
+ # has no load-time bigdecimal dependency.
155
154
  def comparable_bound(value)
156
155
  require "bigdecimal" unless defined?(BigDecimal)
157
156
  BigDecimal(value.to_s)
@@ -8,23 +8,9 @@ module Lutaml
8
8
  # Extracted from serialize.rb to improve code organization.
9
9
  # Provides methods for defining and validating model attributes.
10
10
  module AttributeDefinition
11
- # Whether the per-class accessors and the state-defaults seed are
12
- # compiled from Ruby source with a String class_eval (the fast
13
- # path). Opal has no runtime compiler unless opal-parser is
14
- # bundled, so there every such method is defined from a block
15
- # with define_method instead.
16
- # Core dispatch for the block-form methods, bound per call so an
17
- # attribute or method a model defines with one of these names
18
- # (send, __send__, instance_variable_get, const_get, ...) is never invoked;
19
- # the compiled form reads ivars and calls methods directly.
20
- IVAR_GET = ::Kernel.instance_method(:instance_variable_get)
21
- IVAR_SET = ::Kernel.instance_method(:instance_variable_set)
22
- SEND = ::BasicObject.instance_method(:__send__)
23
- CONST_GET = ::Module.instance_method(:const_get)
24
-
25
- def self.source_compilation?
26
- !Lutaml::Model.opal?
27
- end
11
+ # The per-class accessors and the state-defaults seed are
12
+ # compiled from Ruby source with a String class_eval: the
13
+ # compiled form reads ivars and calls methods directly.
28
14
 
29
15
  # Define attribute methods on the model class
30
16
  #
@@ -62,26 +48,6 @@ module Lutaml
62
48
  return
63
49
  end
64
50
 
65
- unless AttributeDefinition.source_compilation?
66
- seeds = attrs.map do |name, attr|
67
- sentinel = if attr.collection?
68
- Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION
69
- else
70
- Lutaml::Model::UninitializedClass.instance
71
- end
72
- [:"@#{name}", sentinel]
73
- end
74
- # Raw readers for every attribute the register sees, as the
75
- # compiled form below does (#933).
76
- attrs.each_key { |name| define_raw_state_reader(name) }
77
- define_method(method_name) do
78
- # Returns the last seeded value, as the compiled form's final
79
- # assignment does.
80
- seeds.reduce(nil) { |_, (ivar, sentinel)| IVAR_SET.bind_call(self, ivar, sentinel) }
81
- end
82
- return
83
- end
84
-
85
51
  lines = attrs.map do |name, attr|
86
52
  if attr.collection?
87
53
  "@#{name} = Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION"
@@ -188,25 +154,6 @@ module Lutaml
188
154
  "Serialize::DEFAULT_VALUE_MAP)"
189
155
  end
190
156
 
191
- unless AttributeDefinition.source_compilation?
192
- define_method(method_name) do
193
- @using_default = marks
194
- simple.each { |n| IVAR_SET.bind_call(self, :"@#{n}", nil) }
195
- lazy.each do |n|
196
- IVAR_SET.bind_call(
197
- self, :"@#{n}", Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION
198
- )
199
- end
200
- complex.each do |n|
201
- initialize_single_attribute(
202
- {}, n, self.class.attributes(@lutaml_register)[n],
203
- Serialize::DEFAULT_VALUE_MAP
204
- )
205
- end
206
- end
207
- return
208
- end
209
-
210
157
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1) # rubocop:disable Style/DocumentDynamicEvalDefinition
211
158
  def #{method_name}
212
159
  #{marks_line}
@@ -217,14 +164,6 @@ module Lutaml
217
164
  RUBY
218
165
  end
219
166
 
220
- # Block-form raw-state reader (no String eval), defined on self.
221
- def define_raw_state_reader(name)
222
- ivar = :"@#{name}"
223
- define_method(:"__lutaml_raw_#{name}") do
224
- IVAR_GET.bind_call(self, ivar)
225
- end
226
- end
227
-
228
167
  # Historical getter shape for punctuation-named attributes and
229
168
  # any name the compiled form cannot express.
230
169
  def define_reflective_attribute_methods(name, attr)
@@ -255,15 +194,8 @@ module Lutaml
255
194
  end
256
195
 
257
196
  def invalidate_state_defaults!
258
- # Opal's method_defined? takes no inherit flag (see the
259
- # setter_defined check in define_regular_attribute_methods).
260
197
  (@state_defaults_names ||= {}).each_key do |compiled|
261
- defined_now = if Lutaml::Model.opal?
262
- method_defined?(compiled)
263
- else
264
- method_defined?(compiled, false)
265
- end
266
- remove_method(compiled) if defined_now
198
+ remove_method(compiled) if method_defined?(compiled, false)
267
199
  end
268
200
  # The names cache must go with the methods: the memoized
269
201
  # lookup answers stale names for removed methods otherwise.
@@ -288,16 +220,11 @@ module Lutaml
288
220
  # the state-defaults compilation) so late declarations get it
289
221
  # too -- XMI's extension loader declares attributes after
290
222
  # first parse.
291
- # Without a source compiler, compile_state_defaults! defines
292
- # its raw readers from blocks; define one for every name here
293
- # too (define_method takes any name, not only plain ones).
294
- # Both forms define on self: a bare `model` receiver resolves
223
+ # Defined on self: a bare `model` receiver resolves
295
224
  # through the host class's own namespace (omml's Base answers
296
225
  # a Store model) and defined the reader on the wrong object
297
226
  # (#933).
298
- if !AttributeDefinition.source_compilation?
299
- define_raw_state_reader(name)
300
- elsif name.to_s.match?(PLAIN_NAME)
227
+ if name.to_s.match?(PLAIN_NAME)
301
228
  class_eval(<<~RUBY, __FILE__, __LINE__ + 1) # rubocop:disable Style/DocumentDynamicEvalDefinition
302
229
  def __lutaml_raw_#{name}
303
230
  @#{name}
@@ -411,9 +338,7 @@ module Lutaml
411
338
  # Array on EVERY read — the largest per-call allocation source
412
339
  # on instance-heavy parses (TODO.max-perf/06). The optional-arg
413
340
  # form allocates nothing, and the read is a direct @ivar.
414
- if !AttributeDefinition.source_compilation?
415
- define_block_attribute_getter(name, attr)
416
- elsif attr.collection?
341
+ if attr.collection?
417
342
  # class_eval interpolates, e.g.:
418
343
  # def items(arg = Lutaml::Model::Serialize::NO_ARG)
419
344
  # if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
@@ -449,29 +374,16 @@ module Lutaml
449
374
  end
450
375
 
451
376
  enum_shorthand_names = instance_variable_get(:@__enum_shorthand_names__) || Set.new
452
- # Opal's Module#method_defined? only accepts 1 arg (MRI accepts
453
- # the optional `inherit` flag). Skip the flag there — the
454
- # difference only matters for inherited-method filtering.
455
- setter_defined = if Lutaml::Model.opal?
456
- method_defined?(:"#{name}=")
457
- else
458
- method_defined?(:"#{name}=", false)
459
- end
377
+ setter_defined = method_defined?(:"#{name}=", false)
460
378
  return if setter_defined && !enum_shorthand_names.include?(name.to_s)
461
379
 
462
380
  # class_eval'd bodies cannot close over locals; a hidden
463
381
  # define_method accessor holds the Attribute handle.
464
382
  attr_reader_method = :"__attribute_definition_#{name}"
465
- reader_defined = if Lutaml::Model.opal?
466
- method_defined?(attr_reader_method)
467
- else
468
- method_defined?(attr_reader_method, false)
469
- end
383
+ reader_defined = method_defined?(attr_reader_method, false)
470
384
  define_method(attr_reader_method) { attr } unless reader_defined
471
385
 
472
- if !AttributeDefinition.source_compilation?
473
- define_block_attribute_setters(name, attr)
474
- elsif attr.collection? && !attr.lazy_collection_default?
386
+ if attr.collection? && !attr.lazy_collection_default?
475
387
  # class_eval interpolates, e.g.:
476
388
  # def items=(value)
477
389
  # value_set_for(:items)
@@ -550,92 +462,6 @@ module Lutaml
550
462
  end
551
463
  end
552
464
 
553
- # Block form of the compiled getter in define_regular_attribute_methods,
554
- # for runtimes without a source compiler (see source_compilation?).
555
- def define_block_attribute_getter(name, attr)
556
- name = name.to_sym # the compiled form passes :name literals
557
- ivar = :"@#{name}"
558
- if attr.collection?
559
- # The compiled getter resolves Array in the model class's scope.
560
- scope = self
561
- define_method(name) do |arg = Lutaml::Model::Serialize::NO_ARG|
562
- if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
563
- materialize_lazy_collection(name)
564
- else
565
- current = IVAR_GET.bind_call(self, ivar) || []
566
- new_value = current.is_a?(CONST_GET.bind_call(scope, :Array)) ? current + [arg] : arg
567
- IVAR_SET.bind_call(self, ivar, new_value)
568
- record_mutation(name, arg)
569
- arg
570
- end
571
- end
572
- else
573
- define_method(name) do |arg = Lutaml::Model::Serialize::NO_ARG|
574
- if arg.equal?(Lutaml::Model::Serialize::NO_ARG)
575
- IVAR_GET.bind_call(self, ivar)
576
- else
577
- public_send(:"#{name}=", arg)
578
- arg
579
- end
580
- end
581
- end
582
- end
583
-
584
- # Block form of the compiled setters in define_regular_attribute_methods.
585
- # The Attribute is read through the same hidden accessor the
586
- # compiled form calls, not captured: a setter redefined over an
587
- # enum shorthand keeps casting with the accessor's Attribute.
588
- def define_block_attribute_setters(name, attr)
589
- name = name.to_sym # the compiled form passes :name literals
590
- ivar = :"@#{name}"
591
- handle = :"__attribute_definition_#{name}"
592
- if attr.collection? && !attr.lazy_collection_default?
593
- assign = lambda do |model, value|
594
- current = IVAR_GET.bind_call(model, ivar)
595
- unless current.equal?(Lutaml::Model::Serialize::LAZY_EMPTY_COLLECTION) &&
596
- (value.nil? || Lutaml::Model::Utils.uninitialized?(value))
597
- IVAR_SET.bind_call(model, ivar, value)
598
- end
599
- SEND.bind_call(model, :record_mutation_collection, name, value)
600
- end
601
- define_method(:"#{name}=") do |value|
602
- value_set_for(name)
603
- assign.call(self, SEND.bind_call(self, handle).cast_value(value, lutaml_register))
604
- end
605
- define_method(:"__assign_parsed_#{name}=") do |value|
606
- value_set_for(name)
607
- assign.call(self, value)
608
- end
609
- elsif attr.collection?
610
- # Lazy-seeded default collections (#1010): nil lands over the
611
- # sentinel — see the source-compiled branch.
612
- assign = lambda do |model, value|
613
- IVAR_SET.bind_call(model, ivar, value)
614
- SEND.bind_call(model, :record_mutation_collection, name, value)
615
- end
616
- define_method(:"#{name}=") do |value|
617
- value_set_for(name)
618
- assign.call(self, SEND.bind_call(self, handle).cast_value(value, lutaml_register))
619
- end
620
- define_method(:"__assign_parsed_#{name}=") do |value|
621
- value_set_for(name)
622
- assign.call(self, value)
623
- end
624
- else
625
- define_method(:"#{name}=") do |value|
626
- value_set_for(name)
627
- value = SEND.bind_call(self, handle).cast_value(value, lutaml_register)
628
- IVAR_SET.bind_call(self, ivar, value)
629
- record_mutation(name, value)
630
- end
631
- define_method(:"__assign_parsed_#{name}=") do |value|
632
- value_set_for(name)
633
- IVAR_SET.bind_call(self, ivar, value)
634
- record_mutation(name, value)
635
- end
636
- end
637
- end
638
-
639
465
  # Class-level documentation metadata (#356): `desc "text"` on
640
466
  # the model class; a zero-argument call reads it back.
641
467
  # Subclasses inherit the nearest ancestor's description — an
@@ -42,10 +42,7 @@ module Lutaml
42
42
  # - A hit returns before the wrapped body runs, so option-hash
43
43
  # mutations the body performs on a miss (e.g. consuming :adapter)
44
44
  # do not happen on a hit.
45
- # - Caching is disabled under Opal: keys need native Marshal/Digest.
46
45
  module ConversionCaching
47
- NATIVE_RUNTIME = !Lutaml::Model::RuntimeCompatibility.opal?
48
-
49
46
  UNMARSHALABLE_IVAR = :@__lutaml_conversion_cache_unmarshalable
50
47
 
51
48
  def cache_conversions
@@ -75,8 +72,7 @@ module Lutaml
75
72
  end
76
73
 
77
74
  def conversion_cache_store(options)
78
- unless NATIVE_RUNTIME && conversion_caching_enabled? &&
79
- options.is_a?(::Hash)
75
+ unless conversion_caching_enabled? && options.is_a?(::Hash)
80
76
  return
81
77
  end
82
78
 
@@ -305,11 +305,6 @@ module Lutaml
305
305
  # Uses TracePoint to detect when a class definition is complete,
306
306
  # allowing deferred import resolution.
307
307
  def setup_trace_point
308
- # Opal has no TracePoint. Symbol imports still resolve lazily
309
- # on first use (ensure_imports!), so there the class is marked
310
- # finalized at once instead of at the end of its body.
311
- return @finalized = true if Lutaml::Model.opal?
312
-
313
308
  @trace ||= TracePoint.new(:end) do |_tp|
314
309
  if include?(Lutaml::Model::Serialize)
315
310
  @finalized = true
@@ -108,9 +108,6 @@ module Lutaml
108
108
  def ensure_utf8(value)
109
109
  case value
110
110
  when String
111
- # Opal strings are JS strings with no per-string encoding;
112
- # String#encode there doesn't accept MRI's keyword options.
113
- return value if Lutaml::Model.opal?
114
111
  # The encode-with-options forces a fresh copy per value even
115
112
  # when the string is already valid UTF-8 — the overwhelming
116
113
  # case on parsed documents. Scan instead: no allocation on