lutaml-model 0.8.201 → 0.8.203
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/dependent-tests.yml +59 -2
- 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/plan-schema-spec.adoc +45 -18
- 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 +149 -37
- 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 +11 -6
- 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/deserialization_context.rb +21 -0
- data/lib/lutaml/model/serialize/initialization.rb +19 -9
- 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/address_person_spec.rb +8 -0
- data/spec/address_spec.rb +4 -0
- data/spec/benchmarks/xml_parsing_benchmark_spec.rb +1 -1
- data/spec/lutaml/json/adapter/standard_adapter_spec.rb +6 -9
- data/spec/lutaml/key_value/group_instantiate_spec.rb +204 -1
- 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/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/serialize/deserialization_context_spec.rb +68 -0
- 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 +8 -28
- data/spec/support/test_adapter_config.rb +6 -6
- metadata +2 -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
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Vendored from lutaml/moxml 0.5.167's lib/compat/opal/rexml_compat.rb
|
|
4
|
-
# (the compat surface moxml 0.6 no longer ships). The shadows under
|
|
5
|
-
# rexml/ patch the REXML stdlib gem for Opal — multi-byte escape
|
|
6
|
-
# regexes in rexml/source.rb, namespace resolution, text decoding and
|
|
7
|
-
# the baseparser scanner — which the Opal boot requires on every
|
|
8
|
-
# moxml line. Loaded by the Opal Rakefile before spec_helper.
|
|
9
|
-
require "corelib/array/pack"
|
|
10
|
-
|
|
11
|
-
# backtick_javascript: true
|
|
12
|
-
|
|
13
|
-
require "corelib/array/pack"
|
|
14
|
-
|
|
15
|
-
unless defined?(StringScanner::Version)
|
|
16
|
-
class StringScanner
|
|
17
|
-
Version = "3.0.8"
|
|
18
|
-
end
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
unless String.method_defined?(:force_encoding)
|
|
22
|
-
class String
|
|
23
|
-
def force_encoding(*)
|
|
24
|
-
self
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
unless defined?(Encoding)
|
|
30
|
-
module ::Encoding
|
|
31
|
-
UTF_8 = "UTF-8"
|
|
32
|
-
ASCII_8BIT = "ASCII-8BIT"
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
unless String.method_defined?(:encode)
|
|
37
|
-
class String
|
|
38
|
-
def encode(*)
|
|
39
|
-
self
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
# Opal defines mutable String methods as raising NotImplementedError.
|
|
45
|
-
# Override with functional equivalents that return new strings.
|
|
46
|
-
class String
|
|
47
|
-
def <<(str)
|
|
48
|
-
`return self + #{str}.to_s`
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def chomp!(sep = nil)
|
|
52
|
-
`
|
|
53
|
-
var r = #{chomp(sep)};
|
|
54
|
-
return r === self ? nil : r;
|
|
55
|
-
`
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
def gsub!(pattern, replacement, &block)
|
|
59
|
-
`
|
|
60
|
-
var r = #{gsub(pattern, replacement, &block)};
|
|
61
|
-
return r === self ? nil : r;
|
|
62
|
-
`
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def squeeze!(*sets)
|
|
66
|
-
`
|
|
67
|
-
var r = #{squeeze(*sets)};
|
|
68
|
-
return r === self ? nil : r;
|
|
69
|
-
`
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def strip!
|
|
73
|
-
`
|
|
74
|
-
var r = #{strip};
|
|
75
|
-
return r === self ? nil : r;
|
|
76
|
-
`
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
class StringIO
|
|
81
|
-
def <<(str)
|
|
82
|
-
write(str)
|
|
83
|
-
self
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
# Opal runtime YAML compat.
|
|
4
|
-
#
|
|
5
|
-
# Opal's `nodejs/yaml` ships `YAML.load` only. lutaml-model's YAML adapter
|
|
6
|
-
# uses `YAML.safe_load(src, permitted_classes: [...])` and `YAML.dump(obj)`.
|
|
7
|
-
# Provide both as thin wrappers — nodejs/yaml is already backed by
|
|
8
|
-
# jsyaml.safeLoad, so `load` semantics are equivalent to MRI's safe_load
|
|
9
|
-
# with the default permitted classes (the perm_classes argument is
|
|
10
|
-
# accepted but ignored, matching Opal's stronger-by-default posture).
|
|
11
|
-
|
|
12
|
-
if RUBY_ENGINE == "opal"
|
|
13
|
-
require "nodejs/yaml"
|
|
14
|
-
|
|
15
|
-
module ::YAML
|
|
16
|
-
class << self
|
|
17
|
-
# Accept MRI's full safe_load kwargs for API parity; nodejs/yaml's
|
|
18
|
-
# safeLoad is already safe-by-default so the kwargs are unused.
|
|
19
|
-
def safe_load(yaml, **_kwargs)
|
|
20
|
-
load(yaml)
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def dump(obj, io = nil)
|
|
24
|
-
dumped = `#{@__yaml__}.safeDump(#{obj})`
|
|
25
|
-
return dumped unless io
|
|
26
|
-
|
|
27
|
-
io.write(dumped)
|
|
28
|
-
io
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
end
|
|
32
|
-
end
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Lutaml
|
|
4
|
-
module Model
|
|
5
|
-
class CachedTypeResolver
|
|
6
|
-
# Hash-backed cache that only relies on Mutex semantics available on Opal.
|
|
7
|
-
class MutexHashCache
|
|
8
|
-
def initialize(store: {}, mutex: Mutex.new)
|
|
9
|
-
@store = store
|
|
10
|
-
@mutex = mutex
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def fetch_or_store(cache_key)
|
|
14
|
-
found = false
|
|
15
|
-
cached_value = @mutex.synchronize do
|
|
16
|
-
if @store.key?(cache_key)
|
|
17
|
-
found = true
|
|
18
|
-
@store[cache_key]
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
return cached_value if found
|
|
22
|
-
|
|
23
|
-
value = yield
|
|
24
|
-
|
|
25
|
-
@mutex.synchronize do
|
|
26
|
-
@store[cache_key] = value unless @store.key?(cache_key)
|
|
27
|
-
@store[cache_key]
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def key?(cache_key)
|
|
32
|
-
@mutex.synchronize { @store.key?(cache_key) }
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
def clear_context(context_id)
|
|
36
|
-
@mutex.synchronize do
|
|
37
|
-
# Non-Array keys are the bare, nil-context form (see
|
|
38
|
-
# CachedTypeResolver#type_cache_key).
|
|
39
|
-
@store.delete_if { |key, _| (key.is_a?(Array) ? key[0] : nil) == context_id }
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def clear
|
|
44
|
-
@mutex.synchronize { @store.clear }
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def keys
|
|
48
|
-
@mutex.synchronize { @store.keys.dup }
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "oga"
|
|
4
|
-
|
|
5
|
-
module Lutaml
|
|
6
|
-
module Model
|
|
7
|
-
module Schema
|
|
8
|
-
class SchemaBuilder
|
|
9
|
-
# Oga adapter for XSD schema generation
|
|
10
|
-
# Wraps Oga XML building to provide schema building capabilities
|
|
11
|
-
class Oga
|
|
12
|
-
attr_reader :builder, :document
|
|
13
|
-
|
|
14
|
-
def initialize(options = {})
|
|
15
|
-
@encoding = options[:encoding] || "UTF-8"
|
|
16
|
-
@document = ::Oga::XML::Document.new
|
|
17
|
-
@builder = OgaBuilderWrapper.new(@document, @encoding)
|
|
18
|
-
|
|
19
|
-
# Execute the block if provided
|
|
20
|
-
yield(@builder) if block_given?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Generate the XSD schema XML string
|
|
24
|
-
# @param options [Hash] formatting options
|
|
25
|
-
# @option options [Boolean] :pretty Pretty print with indentation (note: Oga doesn't support pretty printing directly)
|
|
26
|
-
# @return [String] XSD XML string
|
|
27
|
-
def to_xml(_options = {})
|
|
28
|
-
xml = @document.to_xml
|
|
29
|
-
# Add XML declaration with encoding
|
|
30
|
-
"<?xml version=\"1.0\" encoding=\"#{@encoding}\"?>\n#{xml}"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Forward all other methods to the builder wrapper
|
|
34
|
-
def method_missing(method_name, ...)
|
|
35
|
-
@builder.public_send(method_name, ...)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
39
|
-
@builder.respond_to?(method_name, include_private) || super
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Wrapper that provides a Nokogiri-like API for Oga
|
|
43
|
-
class OgaBuilderWrapper
|
|
44
|
-
def initialize(document, encoding)
|
|
45
|
-
@document = document
|
|
46
|
-
@encoding = encoding
|
|
47
|
-
@current_element = nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Create a method that acts like Nokogiri's builder DSL
|
|
51
|
-
# e.g., xml.schema { } or xml.element { }
|
|
52
|
-
def method_missing(method_name, *args)
|
|
53
|
-
attributes = args.first || {}
|
|
54
|
-
|
|
55
|
-
# Create the element
|
|
56
|
-
element = ::Oga::XML::Element.new(name: method_name.to_s)
|
|
57
|
-
|
|
58
|
-
# Add attributes
|
|
59
|
-
attributes.each do |name, value|
|
|
60
|
-
element.attributes << ::Oga::XML::Attribute.new(
|
|
61
|
-
name: name.to_s,
|
|
62
|
-
value: value.to_s,
|
|
63
|
-
)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Add to document or current element
|
|
67
|
-
if @current_element
|
|
68
|
-
@current_element.children << element
|
|
69
|
-
else
|
|
70
|
-
@document.children << element
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# If block given, process nested elements
|
|
74
|
-
if block_given?
|
|
75
|
-
parent = @current_element
|
|
76
|
-
@current_element = element
|
|
77
|
-
yield
|
|
78
|
-
@current_element = parent
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
element
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def respond_to_missing?(_method_name, _include_private = false)
|
|
85
|
-
true # Accept any method for element creation
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "oga"
|
|
4
|
-
|
|
5
|
-
module Lutaml
|
|
6
|
-
module Xml
|
|
7
|
-
module Schema
|
|
8
|
-
class Builder
|
|
9
|
-
# Oga adapter for XSD schema generation
|
|
10
|
-
# Wraps Oga XML building to provide schema building capabilities
|
|
11
|
-
class Oga
|
|
12
|
-
attr_reader :document
|
|
13
|
-
|
|
14
|
-
def initialize(options = {})
|
|
15
|
-
@encoding = options[:encoding] || "UTF-8"
|
|
16
|
-
@document = ::Oga::XML::Document.new
|
|
17
|
-
@builder = OgaBuilderWrapper.new(@document, @encoding)
|
|
18
|
-
|
|
19
|
-
# Execute the block if provided
|
|
20
|
-
yield(@builder) if block_given?
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# Generate the XSD schema XML string
|
|
24
|
-
# @param options [Hash] formatting options
|
|
25
|
-
# @option options [Boolean] :pretty Pretty print with indentation
|
|
26
|
-
# @return [String] XSD XML string
|
|
27
|
-
def to_xml(_options = {})
|
|
28
|
-
xml = @document.to_xml
|
|
29
|
-
# Add XML declaration with encoding
|
|
30
|
-
"<?xml version=\"1.0\" encoding=\"#{@encoding}\"?>\n#{xml}"
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
# Forward all other methods to the builder wrapper
|
|
34
|
-
def method_missing(method_name, ...)
|
|
35
|
-
@builder.public_send(method_name, ...)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def respond_to_missing?(method_name, include_private = false)
|
|
39
|
-
@builder.respond_to?(method_name, include_private) || super
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
# Wrapper that provides a Nokogiri-like API for Oga
|
|
43
|
-
class OgaBuilderWrapper
|
|
44
|
-
def initialize(document, encoding)
|
|
45
|
-
@document = document
|
|
46
|
-
@encoding = encoding
|
|
47
|
-
@current_element = nil
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
# Create a method that acts like Nokogiri's builder DSL
|
|
51
|
-
# e.g., xml.schema { } or xml.element { }
|
|
52
|
-
def method_missing(method_name, *args)
|
|
53
|
-
attributes = args.first || {}
|
|
54
|
-
|
|
55
|
-
# Create the element
|
|
56
|
-
element = ::Oga::XML::Element.new(name: method_name.to_s)
|
|
57
|
-
|
|
58
|
-
# Add attributes
|
|
59
|
-
attributes.each do |name, value|
|
|
60
|
-
element.attributes << ::Oga::XML::Attribute.new(
|
|
61
|
-
name: name.to_s,
|
|
62
|
-
value: value.to_s,
|
|
63
|
-
)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
# Add to document or current element
|
|
67
|
-
if @current_element
|
|
68
|
-
@current_element.children << element
|
|
69
|
-
else
|
|
70
|
-
@document.children << element
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
# If block given, process nested elements
|
|
74
|
-
if block_given?
|
|
75
|
-
parent = @current_element
|
|
76
|
-
@current_element = element
|
|
77
|
-
yield
|
|
78
|
-
@current_element = parent
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
element
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
def respond_to_missing?(_method_name, _include_private = false)
|
|
85
|
-
true # Accept any method for element creation
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
end
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
end
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
require "tmpdir"
|
|
5
|
-
|
|
6
|
-
# Guard: the generated Opal boot manifest must stay in sync with the autoloads
|
|
7
|
-
# in lib/lutaml/**. Opal ignores `autoload`, so lutaml_model_boot.rb explicitly
|
|
8
|
-
# requires every autoload target; a deleted/renamed file leaves a stale require
|
|
9
|
-
# that only fails the Opal CI job (`rake spec:opal`) — MRI's autoload hides it.
|
|
10
|
-
# Regenerating here and comparing catches that drift in the fast MRI suite.
|
|
11
|
-
RSpec.describe "Opal boot manifest" do
|
|
12
|
-
let(:generator) do
|
|
13
|
-
File.expand_path("../../../lib/compat/opal/generate_boot.rb", __dir__)
|
|
14
|
-
end
|
|
15
|
-
let(:manifest) do
|
|
16
|
-
File.expand_path("../../../lib/compat/opal/lutaml_model_boot.rb", __dir__)
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
it "matches the generator output (regenerate: ruby lib/compat/opal/generate_boot.rb)" do
|
|
20
|
-
Dir.mktmpdir do |dir|
|
|
21
|
-
out = File.join(dir, "boot.rb")
|
|
22
|
-
ok = system({ "OPAL_BOOT_OUTPUT" => out }, RbConfig.ruby, generator,
|
|
23
|
-
out: File::NULL, err: File::NULL)
|
|
24
|
-
expect(ok).to be(true), "generate_boot.rb failed to run"
|
|
25
|
-
expect(File.read(manifest)).to eq(File.read(out)),
|
|
26
|
-
"lib/compat/opal/lutaml_model_boot.rb is out of date — run " \
|
|
27
|
-
"`ruby lib/compat/opal/generate_boot.rb` after adding/removing autoloads"
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "spec_helper"
|
|
4
|
-
|
|
5
|
-
RSpec.describe "Opal compatibility", if: RUBY_ENGINE == "opal" do
|
|
6
|
-
it "includes Serialize in a class" do
|
|
7
|
-
klass = Class.new { include Lutaml::Model::Serialize }
|
|
8
|
-
expect(klass.include?(Lutaml::Model::Serialize)).to be true
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
it "defines attributes and serializes to hash" do
|
|
12
|
-
person = Class.new do
|
|
13
|
-
include Lutaml::Model::Serialize
|
|
14
|
-
|
|
15
|
-
attribute :name, :string
|
|
16
|
-
attribute :age, :integer
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
instance = person.new(name: "Alice", age: 30)
|
|
20
|
-
expect(instance.to_hash).to eq({ "name" => "Alice", "age" => 30 })
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
it "round-trips JSON serialization" do
|
|
24
|
-
person = Class.new do
|
|
25
|
-
include Lutaml::Model::Serialize
|
|
26
|
-
|
|
27
|
-
attribute :name, :string
|
|
28
|
-
attribute :age, :integer
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
instance = person.from_json('{"name":"Bob","age":25}')
|
|
32
|
-
expect(instance.name).to eq("Bob")
|
|
33
|
-
expect(instance.age).to eq(25)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
it "handles collections" do
|
|
37
|
-
team = Class.new do
|
|
38
|
-
include Lutaml::Model::Serialize
|
|
39
|
-
|
|
40
|
-
attribute :members, :string, collection: true
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
instance = team.new(members: %w[Alice Bob Carol])
|
|
44
|
-
expect(instance.members).to eq(%w[Alice Bob Carol])
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
it "handles defaults" do
|
|
48
|
-
widget = Class.new do
|
|
49
|
-
include Lutaml::Model::Serialize
|
|
50
|
-
|
|
51
|
-
attribute :name, :string
|
|
52
|
-
attribute :active, :boolean, default: -> { true }
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
instance = widget.new(name: "test")
|
|
56
|
-
expect(instance.active).to be true
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it "handles type coercion" do
|
|
60
|
-
record = Class.new do
|
|
61
|
-
include Lutaml::Model::Serialize
|
|
62
|
-
|
|
63
|
-
attribute :count, :integer
|
|
64
|
-
attribute :ratio, :float
|
|
65
|
-
attribute :flag, :boolean
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
instance = record.new(count: "42", ratio: "3.14", flag: "true")
|
|
69
|
-
expect(instance.count).to eq(42)
|
|
70
|
-
expect(instance.ratio).to eq(3.14)
|
|
71
|
-
expect(instance.flag).to be true
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it "resolves scalar union attributes" do
|
|
75
|
-
reading = Class.new do
|
|
76
|
-
include Lutaml::Model::Serialize
|
|
77
|
-
|
|
78
|
-
attribute :value, %i[integer string]
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
expect(reading.from_json('{"value":42}').value).to eq(42)
|
|
82
|
-
expect(reading.from_json('{"value":"hot"}').value).to eq("hot")
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "resolves a union of a model member and a scalar" do
|
|
86
|
-
temperature = Class.new do
|
|
87
|
-
include Lutaml::Model::Serialize
|
|
88
|
-
|
|
89
|
-
attribute :celsius, :float
|
|
90
|
-
end
|
|
91
|
-
holder = Class.new do
|
|
92
|
-
include Lutaml::Model::Serialize
|
|
93
|
-
|
|
94
|
-
attribute :temp, [temperature, :string]
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
structured = holder.from_json('{"temp":{"celsius":12.5}}')
|
|
98
|
-
expect(structured.temp).to be_a(temperature)
|
|
99
|
-
expect(structured.temp.celsius).to eq(12.5)
|
|
100
|
-
expect(holder.from_json('{"temp":"cold"}').temp).to eq("cold")
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
it "validates a pattern on a union :string member" do
|
|
104
|
-
coded = Class.new do
|
|
105
|
-
include Lutaml::Model::Serialize
|
|
106
|
-
|
|
107
|
-
attribute :code, %i[integer string], pattern: /\A[A-Z]+\z/
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
expect(coded.new(code: "ABC").validate).to be_empty
|
|
111
|
-
expect(coded.new(code: "abc").validate).not_to be_empty
|
|
112
|
-
expect(coded.new(code: 42).validate).to be_empty
|
|
113
|
-
end
|
|
114
|
-
|
|
115
|
-
it "handles nested models" do
|
|
116
|
-
address = Class.new do
|
|
117
|
-
include Lutaml::Model::Serialize
|
|
118
|
-
|
|
119
|
-
attribute :city, :string
|
|
120
|
-
attribute :zip, :string
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
person = Class.new do
|
|
124
|
-
include Lutaml::Model::Serialize
|
|
125
|
-
|
|
126
|
-
attribute :name, :string
|
|
127
|
-
attribute :address, address
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
instance = person.new(name: "Alice",
|
|
131
|
-
address: address.new(
|
|
132
|
-
city: "NYC", zip: "10001",
|
|
133
|
-
))
|
|
134
|
-
expect(instance.address.city).to eq("NYC")
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it "handles YAML serialization" do
|
|
138
|
-
config = Class.new do
|
|
139
|
-
include Lutaml::Model::Serialize
|
|
140
|
-
|
|
141
|
-
attribute :host, :string
|
|
142
|
-
attribute :port, :integer
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
instance = config.from_yaml("host: localhost\nport: 8080\n")
|
|
146
|
-
expect(instance.host).to eq("localhost")
|
|
147
|
-
expect(instance.port).to eq(8080)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
# Opal has no TracePoint; a symbol import is resolved on first use.
|
|
151
|
-
it "resolves a deferred symbol import on first use" do
|
|
152
|
-
register = Lutaml::Model::GlobalRegister
|
|
153
|
-
.lookup(Lutaml::Model::Config.default_register)
|
|
154
|
-
importer = Class.new(Lutaml::Model::Serializable) do
|
|
155
|
-
import_model :opal_deferred_import
|
|
156
|
-
end
|
|
157
|
-
imported = Class.new(Lutaml::Model::Serializable) do
|
|
158
|
-
attribute :title, :string
|
|
159
|
-
end
|
|
160
|
-
register.register_model(imported, id: :opal_deferred_import)
|
|
161
|
-
|
|
162
|
-
instance = importer.from_json('{"title":"Deferred"}')
|
|
163
|
-
expect(instance.title).to eq("Deferred")
|
|
164
|
-
expect(instance.to_hash).to eq({ "title" => "Deferred" })
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
it "RuntimeCompatibility detects Opal" do
|
|
168
|
-
expect(Lutaml::Model::RuntimeCompatibility.opal?).to be true
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it "AdapterResolver auto-detects Oga as the default" do
|
|
172
|
-
adapter = Lutaml::Model::AdapterResolver.detect_xml_adapter
|
|
173
|
-
expect(adapter).to eq(:oga)
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
it "exposes both Oga and REXML as available adapters under Opal" do
|
|
177
|
-
# Both are pure Ruby; Nokogiri and Ox are C extensions and excluded.
|
|
178
|
-
options = Lutaml::Model::FormatRegistry.adapter_options_for(:xml)
|
|
179
|
-
expect(options).not_to be_nil
|
|
180
|
-
|
|
181
|
-
available = options[:available]
|
|
182
|
-
expect(available).to include(:oga, :rexml)
|
|
183
|
-
expect(available).not_to include(:nokogiri, :ox)
|
|
184
|
-
end
|
|
185
|
-
|
|
186
|
-
# Opal's Module#prepend raises "Prepending a module multiple times
|
|
187
|
-
# is not supported" on the second call; runtime_compatibility.rb
|
|
188
|
-
# patches it to match MRI's idempotent behavior. Top-level lib files
|
|
189
|
-
# (lib/lutaml/model.rb, lib/lutaml/xml.rb) rely on this when Opal's
|
|
190
|
-
# eager loader re-evaluates them.
|
|
191
|
-
it "Module#prepend is idempotent under Opal" do
|
|
192
|
-
mod = Module.new
|
|
193
|
-
klass = Class.new
|
|
194
|
-
klass.prepend(mod)
|
|
195
|
-
|
|
196
|
-
expect { klass.prepend(mod) }.not_to raise_error
|
|
197
|
-
expect(klass.ancestors.count(mod)).to eq(1)
|
|
198
|
-
end
|
|
199
|
-
end
|