lutaml-model 0.8.200 → 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.
- checksums.yaml +4 -4
- data/.github/scripts/test_installed_gem.rb +1 -13
- data/.github/workflows/downstream-performance.yml +1 -22
- data/.github/workflows/performance.yml +1 -33
- data/.github/workflows/rake.yml +2 -6
- data/.rubocop.yml +0 -10
- data/.rubocop_todo.yml +0 -4
- data/Gemfile +0 -23
- data/README.adoc +25 -86
- data/Rakefile +2 -167
- data/docs/_guides/advanced-mapping.adoc +6 -6
- data/docs/_guides/character-encoding.adoc +0 -3
- data/docs/_guides/gem-integration.adoc +1 -1
- data/docs/_guides/index.adoc +0 -4
- data/docs/_guides/xml/type-namespaces.adoc +1 -1
- data/docs/_guides/xml-guide-0.8.0.adoc +2 -2
- data/docs/_guides/xml-namespaces.adoc +2 -3
- data/docs/_guides/xml_mappings/03_architecture.adoc +2 -2
- data/docs/_guides/xml_mappings/07_best_practices.adoc +2 -3
- data/docs/_guides/xml_mappings/08_troubleshooting.adoc +1 -9
- data/docs/_pages/comparison-with-shale.adoc +1 -1
- data/docs/_pages/configuration.adoc +6 -40
- data/docs/_pages/index.adoc +0 -1
- data/docs/_pages/serialization_adapters.adoc +4 -16
- data/docs/_references/architecture.adoc +1 -1
- data/docs/_references/lutaml-namespace-planning.md +1 -1
- data/docs/_references/three-phase-namespace-architecture.adoc +1 -2
- data/docs/_references/xsd-generation-with-namespace-support.adoc +3 -8
- data/docs/_tutorials/lutaml-xml-architecture.adoc +2 -8
- data/docs/architecture.md +7 -11
- data/docs/conversion_caching.adoc +1 -1
- data/docs/index.adoc +0 -1
- data/docs/key_value_data_model.adoc +1 -1
- data/docs/namespace-management.adoc +4 -10
- data/lib/lutaml/json/format.rb +0 -1
- data/lib/lutaml/json/generator_options.rb +0 -1
- data/lib/lutaml/key_value/transform.rb +9 -16
- data/lib/lutaml/lml/document_builder.rb +2 -2
- data/lib/lutaml/lml/entity_types.rb +2 -2
- data/lib/lutaml/model/adapter_resolver.rb +5 -15
- data/lib/lutaml/model/attribute.rb +14 -2
- data/lib/lutaml/model/cached_type_resolver.rb +1 -7
- data/lib/lutaml/model/error/unknown_adapter_type_error.rb +1 -1
- data/lib/lutaml/model/global_context.rb +3 -5
- data/lib/lutaml/model/instrumentation.rb +0 -3
- data/lib/lutaml/model/mapping/mapping_rule.rb +6 -10
- data/lib/lutaml/model/register.rb +20 -31
- data/lib/lutaml/model/runtime_compatibility.rb +0 -92
- data/lib/lutaml/model/schema/class_loader.rb +2 -4
- data/lib/lutaml/model/schema/xml_compiler/spec_builder/simple_types.rb +2 -3
- data/lib/lutaml/model/serialize/attribute_definition.rb +10 -184
- data/lib/lutaml/model/serialize/conversion_caching.rb +1 -5
- data/lib/lutaml/model/serialize/model_import.rb +0 -5
- data/lib/lutaml/model/serialize/value_mapping.rb +0 -3
- data/lib/lutaml/model/services/rule_value_extractor.rb +4 -7
- data/lib/lutaml/model/store.rb +10 -17
- data/lib/lutaml/model/toml.rb +0 -2
- data/lib/lutaml/model/transformation_registry.rb +3 -7
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model.rb +3 -19
- data/lib/lutaml/toml/format.rb +4 -8
- data/lib/lutaml/xml/adapter/moxml_adapter.rb +1 -7
- data/lib/lutaml/xml/adapter.rb +0 -4
- data/lib/lutaml/xml/adapter_loader.rb +1 -6
- data/lib/lutaml/xml/builder/base.rb +0 -3
- data/lib/lutaml/xml/builder.rb +0 -8
- data/lib/lutaml/xml/data_model.rb +1 -1
- data/lib/lutaml/xml/doctype_extractor.rb +3 -3
- data/lib/lutaml/xml/format.rb +22 -74
- data/lib/lutaml/xml/leptris/plan_compiler.rb +1 -2
- data/lib/lutaml/xml/model_transform.rb +14 -24
- data/lib/lutaml/xml/polymorphic_value_handler.rb +1 -1
- data/lib/lutaml/xml/schema/builder/moxml.rb +1 -1
- data/lib/lutaml/xml/schema/builder.rb +6 -9
- data/lib/lutaml/xml/schema/relaxng_schema.rb +1 -1
- data/lib/lutaml/xml/xml_element.rb +3 -2
- data/lib/lutaml/xml/xsd_validator.rb +4 -11
- data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +2 -2
- data/lib/lutaml/yamls/adapter_loader.rb +1 -5
- data/lib/tasks/performance_comparator.rb +1 -1
- data/lutaml-model.gemspec +3 -8
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
- data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
- data/spec/lutaml/model/adapter_resolver_yeptris_switch_spec.rb +0 -2
- data/spec/lutaml/model/cached_type_resolver_spec.rb +2 -54
- data/spec/lutaml/model/cdata_spec.rb +2 -15
- data/spec/lutaml/model/encoding_spec.rb +0 -9
- data/spec/lutaml/model/except_spec.rb +0 -7
- data/spec/lutaml/model/json_spec.rb +0 -14
- data/spec/lutaml/model/mixed_content_spec.rb +6 -46
- data/spec/lutaml/model/ordered_content_spec.rb +0 -7
- data/spec/lutaml/model/polymorphic_scalar_member_spec.rb +57 -0
- data/spec/lutaml/model/processing_instruction_spec.rb +0 -6
- data/spec/lutaml/model/runtime_compatibility_spec.rb +0 -37
- data/spec/lutaml/model/serializable_spec.rb +0 -2
- data/spec/lutaml/model/toml_spec.rb +0 -23
- data/spec/lutaml/xml/adapter/base_adapter_regression_spec.rb +0 -4
- data/spec/lutaml/xml/adapter/order_spec.rb +1 -1
- data/spec/lutaml/xml/adapter/xml_namespace_spec.rb +0 -7
- data/spec/lutaml/xml/attribute_namespace_disjointness_spec.rb +6 -6
- data/spec/lutaml/xml/builder/builder_spec.rb +0 -24
- data/spec/lutaml/xml/default_namespace_spec.rb +1 -8
- data/spec/lutaml/xml/doctype_preservation_spec.rb +0 -4
- data/spec/lutaml/xml/entity_fragmentation_spec.rb +0 -6
- data/spec/lutaml/xml/fpi_namespace_spec.rb +0 -21
- data/spec/lutaml/xml/mapping_spec.rb +8 -15
- data/spec/lutaml/xml/namespace_scope_vcard_spec.rb +0 -7
- data/spec/lutaml/xml/namespace_spec.rb +0 -13
- data/spec/lutaml/xml/prefix_control_spec.rb +0 -6
- data/spec/lutaml/xml/schema/builder_moxml_spec.rb +1 -1
- data/spec/lutaml/xml/xml_adapter_spec.rb +0 -7
- data/spec/lutaml/xml/xml_spec.rb +2 -88
- data/spec/spec_helper.rb +5 -24
- data/spec/support/test_adapter_config.rb +6 -6
- metadata +1 -32
- data/.github/workflows/js-pr-check.yml +0 -106
- data/.github/workflows/js-sync.yml +0 -55
- data/.github/workflows/opal.yml +0 -65
- data/.gitmodules +0 -6
- data/.rspec-opal +0 -5
- data/docs/_guides/opal.adoc +0 -232
- data/lib/compat/opal/generate_boot.rb +0 -137
- data/lib/compat/opal/js_bundle_entry.rb +0 -42
- data/lib/compat/opal/lutaml_model_boot.rb +0 -638
- data/lib/compat/opal/monitor.rb +0 -31
- data/lib/compat/opal/moxml/adapter/customized_rexml/entity_reference.rb +0 -9
- data/lib/compat/opal/moxml/adapter/customized_rexml/formatter.rb +0 -225
- data/lib/compat/opal/moxml/adapter/customized_rexml.rb +0 -11
- data/lib/compat/opal/moxml_boot.rb +0 -68
- data/lib/compat/opal/objectspace_shim.rb +0 -23
- data/lib/compat/opal/rexml/namespace.rb +0 -59
- data/lib/compat/opal/rexml/parsers/baseparser.rb +0 -1016
- data/lib/compat/opal/rexml/source.rb +0 -214
- data/lib/compat/opal/rexml/text.rb +0 -426
- data/lib/compat/opal/rexml/xmltokens.rb +0 -45
- data/lib/compat/opal/rexml_compat.rb +0 -85
- data/lib/compat/opal/yaml_compat.rb +0 -32
- data/lib/lutaml/model/cached_type_resolver/mutex_hash_cache.rb +0 -53
- data/lib/lutaml/model/schema/schema_builder/oga.rb +0 -92
- data/lib/lutaml/xml/schema/builder/oga.rb +0 -92
- data/spec/lutaml/model/boot_manifest_spec.rb +0 -30
- data/spec/lutaml/model/opal_smoke_spec.rb +0 -199
- data/spec/lutaml/model/serialize/attribute_definition_block_form_spec.rb +0 -244
- data/spec/lutaml/xml/adapter/oga_adapter_spec.rb +0 -135
- data/spec/lutaml/xml/opal_xml_spec.rb +0 -204
- 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
|
|
36
|
-
#
|
|
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 =
|
|
298
|
-
|
|
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
|
|
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
|
|
@@ -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
|
|
@@ -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
|
-
|
|
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
|
|
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
|
|
348
|
-
#
|
|
349
|
-
#
|
|
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
|
-
#
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
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 =
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
|
@@ -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
|
|
153
|
-
#
|
|
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
|
-
#
|
|
12
|
-
# compiled from Ruby source with a String class_eval
|
|
13
|
-
#
|
|
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
|
-
|
|
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
|
-
#
|
|
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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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 !
|
|
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
|