lutaml-model 0.8.181 → 0.8.182
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/lib/compat/opal/lutaml_model_boot.rb +1 -0
- data/lib/lutaml/model/schema/registry_generator.rb +1 -1
- data/lib/lutaml/model/serialize/format_conversion.rb +6 -4
- data/lib/lutaml/model/type/value.rb +15 -0
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/xml/collection_consolidation.rb +44 -0
- data/lib/lutaml/xml/format.rb +1 -0
- data/lib/lutaml/xml/leptris/plan_hydrator.rb +1 -0
- data/lib/lutaml/xml/model_transform.rb +1 -31
- data/lib/lutaml/yaml/adapter/yeptris_adapter.rb +6 -0
- data/spec/fixtures/metanorma_iec_title_consolidation.xml +25 -0
- data/spec/lutaml/model/leptris_consolidation_spec.rb +140 -0
- data/spec/lutaml/model/schema/xml_compiler_runtime_spec.rb +75 -0
- data/spec/lutaml/yaml/yeptris_adapter_spec.rb +3 -0
- metadata +4 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d8dfd6dd5e1c4a29123809356e7558d9bdd7e99a211d066c783b339d7658aeca
|
|
4
|
+
data.tar.gz: 580a207495912f495cf4661224f7f3db965db815c225fd048eeea8ab971e2270
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed454fb7055da28e1ca3a2605e2cdf59c74160f98b82d471f8766aefd3e64a651c9ab5065b5779ba8539342ea2aff1f7dc7a9fbe8751edf9f960aaf5ef423271
|
|
7
|
+
data.tar.gz: bc01ea810e3d79488ce9ba45530254f382d0327d5373cf4337ce7c0fb57739afdc8f3b7252907813b5ca6f6218b4eb20c78e7dee55dee6ca38a871fd3021d234
|
|
@@ -133,6 +133,7 @@ require "lutaml/xml/attribute_namespace_resolver"
|
|
|
133
133
|
require "lutaml/xml/blank_namespace"
|
|
134
134
|
require "lutaml/xml/blank_namespace_handler"
|
|
135
135
|
require "lutaml/xml/builder"
|
|
136
|
+
require "lutaml/xml/collection_consolidation"
|
|
136
137
|
require "lutaml/xml/configurable"
|
|
137
138
|
require "lutaml/xml/data_model"
|
|
138
139
|
require "lutaml/xml/decisions"
|
|
@@ -91,7 +91,7 @@ module Lutaml
|
|
|
91
91
|
id = Utils.snake_case(entry.name).to_sym
|
|
92
92
|
"#{indent}#{class_name} # Trigger autoload\n" \
|
|
93
93
|
"#{indent}context.registry.register(:#{id}, #{class_name})\n" \
|
|
94
|
-
"#{indent}#{class_name}.
|
|
94
|
+
"#{indent}#{class_name}.set_register_context(:#{@register_id})"
|
|
95
95
|
end.join("\n")
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -130,7 +130,7 @@ module Lutaml
|
|
|
130
130
|
raise Lutaml::Model::FormatAdapterNotSpecifiedError.new(format) if adapter.nil?
|
|
131
131
|
|
|
132
132
|
# Resolve imports at the entry point of deserialization
|
|
133
|
-
register = options[:register]
|
|
133
|
+
register = extract_register_id(options[:register])
|
|
134
134
|
|
|
135
135
|
# Hook for format-specific pre-deserialization (e.g., XML mapping import resolution)
|
|
136
136
|
pre_deserialize_hook(format, register)
|
|
@@ -177,7 +177,7 @@ module Lutaml
|
|
|
177
177
|
adapter_name &&= adapter_name.name
|
|
178
178
|
return nil unless adapter_name.to_s.end_with?("LeptrisAdapter")
|
|
179
179
|
|
|
180
|
-
register =
|
|
180
|
+
register = extract_register_id(nil)
|
|
181
181
|
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(self, register)
|
|
182
182
|
return nil unless plan &&
|
|
183
183
|
Lutaml::Xml::Leptris::PlanSerializer.serializable?(plan)
|
|
@@ -206,7 +206,7 @@ module Lutaml
|
|
|
206
206
|
adapter_name = adapter_name&.name
|
|
207
207
|
return nil unless adapter_name.to_s.end_with?("LeptrisAdapter")
|
|
208
208
|
|
|
209
|
-
register =
|
|
209
|
+
register = extract_register_id(nil)
|
|
210
210
|
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(self, register)
|
|
211
211
|
return nil unless plan
|
|
212
212
|
|
|
@@ -453,7 +453,7 @@ module Lutaml
|
|
|
453
453
|
end
|
|
454
454
|
|
|
455
455
|
# Resolve imports at the start of serialization
|
|
456
|
-
register = options[:register]
|
|
456
|
+
register = extract_register_id(options[:register])
|
|
457
457
|
|
|
458
458
|
# Hook for format-specific pre-serialization (e.g., XML mapping import resolution)
|
|
459
459
|
pre_serialize_hook(format, register)
|
|
@@ -461,6 +461,8 @@ module Lutaml
|
|
|
461
461
|
# Recursively resolve child model imports
|
|
462
462
|
ensure_child_imports_resolved!(register)
|
|
463
463
|
|
|
464
|
+
options[:register] = register
|
|
465
|
+
|
|
464
466
|
transformer = Lutaml::Model::Config.transformer_for(format)
|
|
465
467
|
transformer.model_to_data(self, instance, format, options)
|
|
466
468
|
end
|
|
@@ -48,6 +48,21 @@ module Lutaml
|
|
|
48
48
|
@format_type_serializers = {}
|
|
49
49
|
|
|
50
50
|
class << self
|
|
51
|
+
# Set the register context for this type class.
|
|
52
|
+
#
|
|
53
|
+
# Called by derivation registries (RegistryGenerator) so derived
|
|
54
|
+
# types resolve their members (e.g. union memberTypes) in the
|
|
55
|
+
# register they were registered into. Mirrors Serializable's
|
|
56
|
+
# set_register_context contract.
|
|
57
|
+
#
|
|
58
|
+
# @param register_id [Symbol] The register ID
|
|
59
|
+
# @return [void]
|
|
60
|
+
def set_register_context(register_id)
|
|
61
|
+
return if instance_variable_defined?(:@register)
|
|
62
|
+
|
|
63
|
+
@register = register_id
|
|
64
|
+
end
|
|
65
|
+
|
|
51
66
|
# Register a custom type serializer for a specific format and type class.
|
|
52
67
|
# Format plugins call this at load time to register their custom serialization logic.
|
|
53
68
|
#
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Lutaml
|
|
4
|
+
module Xml
|
|
5
|
+
# Shared XML post-processing for interpreted mappings and native plans.
|
|
6
|
+
# Organization belongs to the collection's XML mapping; both parse paths
|
|
7
|
+
# must run it after all attributes, deferred mappings and delegates settle.
|
|
8
|
+
module CollectionConsolidation
|
|
9
|
+
def self.call(instance, register, instance_is_serialize = nil)
|
|
10
|
+
return unless instance_is_serialize || instance.is_a?(::Lutaml::Model::Serialize)
|
|
11
|
+
|
|
12
|
+
instance.class.attributes.each_value do |attr|
|
|
13
|
+
next unless attr.collection?
|
|
14
|
+
next unless attr.custom_collection?
|
|
15
|
+
|
|
16
|
+
collection = instance.public_send(attr.name)
|
|
17
|
+
next unless collection.is_a?(::Lutaml::Model::Collection)
|
|
18
|
+
next unless collection.class.organization
|
|
19
|
+
|
|
20
|
+
mappings = collection.class.mappings_for(:xml, register)
|
|
21
|
+
next unless mappings.is_a?(::Lutaml::Xml::Mapping)
|
|
22
|
+
next if mappings.consolidation_maps.empty?
|
|
23
|
+
|
|
24
|
+
mappings.consolidation_maps.each do |map|
|
|
25
|
+
org = collection.class.organization
|
|
26
|
+
resolved_map = if map.group_class
|
|
27
|
+
map
|
|
28
|
+
else
|
|
29
|
+
::Lutaml::Model::ConsolidationMap.new(
|
|
30
|
+
by: map.by,
|
|
31
|
+
to: map.to,
|
|
32
|
+
group_class: org.group_class,
|
|
33
|
+
rules: map.rules,
|
|
34
|
+
)
|
|
35
|
+
end
|
|
36
|
+
::Lutaml::Model::Consolidation::Engine.run(
|
|
37
|
+
collection, resolved_map, collection.collection
|
|
38
|
+
)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
data/lib/lutaml/xml/format.rb
CHANGED
|
@@ -129,6 +129,7 @@ module Lutaml
|
|
|
129
129
|
autoload :Element, "#{__dir__}/element"
|
|
130
130
|
autoload :NestedCollectionAttribute,
|
|
131
131
|
"#{__dir__}/nested_collection_attribute"
|
|
132
|
+
autoload :CollectionConsolidation, "#{__dir__}/collection_consolidation"
|
|
132
133
|
autoload :ModelTransform, "#{__dir__}/model_transform"
|
|
133
134
|
autoload :ParseSession, "#{__dir__}/parse_session"
|
|
134
135
|
autoload :TypeNamespaceResolver, "#{__dir__}/type_namespace_resolver"
|
|
@@ -1724,37 +1724,7 @@ effective_register = lutaml_register)
|
|
|
1724
1724
|
# @param instance [Serializable] the deserialized model instance
|
|
1725
1725
|
# @param register [Symbol] the register id
|
|
1726
1726
|
def run_consolidation(instance, register, instance_is_serialize = nil)
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
instance.class.attributes.each_value do |attr|
|
|
1730
|
-
next unless attr.collection?
|
|
1731
|
-
next unless attr.custom_collection?
|
|
1732
|
-
|
|
1733
|
-
collection = instance.public_send(attr.name)
|
|
1734
|
-
next unless collection.is_a?(::Lutaml::Model::Collection)
|
|
1735
|
-
next unless collection.class.organization
|
|
1736
|
-
|
|
1737
|
-
mappings = collection.class.mappings_for(:xml, register)
|
|
1738
|
-
next unless mappings.is_a?(::Lutaml::Xml::Mapping)
|
|
1739
|
-
next if mappings.consolidation_maps.empty?
|
|
1740
|
-
|
|
1741
|
-
mappings.consolidation_maps.each do |map|
|
|
1742
|
-
org = collection.class.organization
|
|
1743
|
-
resolved_map = if map.group_class
|
|
1744
|
-
map
|
|
1745
|
-
else
|
|
1746
|
-
::Lutaml::Model::ConsolidationMap.new(
|
|
1747
|
-
by: map.by,
|
|
1748
|
-
to: map.to,
|
|
1749
|
-
group_class: org.group_class,
|
|
1750
|
-
rules: map.rules,
|
|
1751
|
-
)
|
|
1752
|
-
end
|
|
1753
|
-
::Lutaml::Model::Consolidation::Engine.run(
|
|
1754
|
-
collection, resolved_map, collection.collection
|
|
1755
|
-
)
|
|
1756
|
-
end
|
|
1757
|
-
end
|
|
1727
|
+
CollectionConsolidation.call(instance, register, instance_is_serialize)
|
|
1758
1728
|
end
|
|
1759
1729
|
|
|
1760
1730
|
# Check if any child element in the pre-built Set matches the rule.
|
|
@@ -150,6 +150,12 @@ module Lutaml
|
|
|
150
150
|
{ "s" => "line1\nline2", "n" => nil },
|
|
151
151
|
{ "q" => "has: colon", "n" => nil },
|
|
152
152
|
{ "u" => "héllo wörld", "num" => "007", "f" => 1.5, "e" => "" },
|
|
153
|
+
# Under 80 characters but over 80 bytes: Psych folds by
|
|
154
|
+
# character column, so this stays on one line there. An
|
|
155
|
+
# engine that folds by byte column breaks it (glossarist's
|
|
156
|
+
# Russian localized concept).
|
|
157
|
+
{ "cyr" => "процесс поглощения атмосферными газами " \
|
|
158
|
+
"электромагнитного излучения" },
|
|
153
159
|
{ "deep" => { "deeper" => [{ "x" => "y" }, [4, 5]] } },
|
|
154
160
|
{ "multi" => "para one\n\npara two", "dash" => "a - b - c",
|
|
155
161
|
"omitted" => nil },
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<metanorma xmlns="https://www.metanorma.org/ns/standoc" type="presentation" version="2.8.7" schema-version="v2.1.6" flavor="iec">
|
|
3
|
+
<bibdata type="standard">
|
|
4
|
+
<title language="en" type="main">Cereals and pulses — Specifications and test methods — Rice</title>
|
|
5
|
+
|
|
6
|
+
<title language="en" type="title-intro">Cereals and pulses</title>
|
|
7
|
+
|
|
8
|
+
<title language="en" type="title-main">Specifications and test methods</title>
|
|
9
|
+
|
|
10
|
+
<title language="en" type="title-part">Rice</title>
|
|
11
|
+
|
|
12
|
+
<title language="en" type="title-part-prefix">Part 1</title>
|
|
13
|
+
|
|
14
|
+
<title language="fr" type="main">Céréales et légumineuses — Spécification et méthodes d’essai — Riz</title>
|
|
15
|
+
|
|
16
|
+
<title language="fr" type="title-intro">Céréales et légumineuses</title>
|
|
17
|
+
|
|
18
|
+
<title language="fr" type="title-main">Spécification et méthodes d’essai</title>
|
|
19
|
+
|
|
20
|
+
<title language="fr" type="title-part">Riz</title>
|
|
21
|
+
|
|
22
|
+
<title language="fr" type="title-part-prefix">Partie 1</title>
|
|
23
|
+
<docidentifier type="ISO" primary="true">IEC CD 17301-1:2016 ED2</docidentifier><docidentifier type="iso-reference">IEC CD 17301-1:2016 ED2(fr)</docidentifier><docidentifier type="iso-revdate">IEC CD 17301-1:2016-05 ED2(fr)</docidentifier><docidentifier type="URN">urn:iec:std:iec:17301-1:2016:stage-30.92:ed-2:fr</docidentifier><docidentifier type="iso-undated">IEC CD 17301-1 ED2</docidentifier><docidentifier type="iso-with-lang">IEC CD 17301-1:2016 ED2(fr)</docidentifier><docidentifier type="iso-tc">17301</docidentifier><language current="true">fr</language><script current="true">Latn</script></bibdata>
|
|
24
|
+
|
|
25
|
+
</metanorma>
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
# Reduced from the real IEC rice presentation fixture. The public model DSL
|
|
6
|
+
# reproduces its title organization without depending on Metanorma gems.
|
|
7
|
+
module LeptrisConsolidationSpec
|
|
8
|
+
class Namespace < Lutaml::Xml::Namespace
|
|
9
|
+
uri "https://www.metanorma.org/ns/standoc"
|
|
10
|
+
prefix_default "standoc"
|
|
11
|
+
element_form_default :qualified
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class Title < Lutaml::Model::Serializable
|
|
15
|
+
attribute :language, :string
|
|
16
|
+
attribute :kind, :string
|
|
17
|
+
attribute :value, :string
|
|
18
|
+
|
|
19
|
+
xml do
|
|
20
|
+
element "title"
|
|
21
|
+
namespace Namespace
|
|
22
|
+
map_attribute "language", to: :language
|
|
23
|
+
map_attribute "type", to: :kind
|
|
24
|
+
map_content to: :value
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class LocalizedTitle < Lutaml::Model::Serializable
|
|
29
|
+
attribute :language, :string
|
|
30
|
+
attribute :full, Title
|
|
31
|
+
attribute :intro, Title
|
|
32
|
+
attribute :main, Title
|
|
33
|
+
attribute :part, Title
|
|
34
|
+
attribute :part_prefix, Title
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class Titles < Lutaml::Model::Collection
|
|
38
|
+
instances :items, Title
|
|
39
|
+
organizes :per_language, LocalizedTitle
|
|
40
|
+
|
|
41
|
+
xml do
|
|
42
|
+
element "titles"
|
|
43
|
+
namespace Namespace
|
|
44
|
+
map_instances to: :items
|
|
45
|
+
consolidate_map by: :language, to: :per_language do
|
|
46
|
+
gather :language, to: :language
|
|
47
|
+
dispatch_by :kind do
|
|
48
|
+
route "main" => :full
|
|
49
|
+
route "title-intro" => :intro
|
|
50
|
+
route "title-main" => :main
|
|
51
|
+
route "title-part" => :part
|
|
52
|
+
route "title-part-prefix" => :part_prefix
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class Bibdata < Lutaml::Model::Serializable
|
|
59
|
+
attribute :titles, Title, collection: Titles
|
|
60
|
+
|
|
61
|
+
xml do
|
|
62
|
+
element "bibdata"
|
|
63
|
+
namespace Namespace
|
|
64
|
+
map_element "title", to: :titles
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
class Document < Lutaml::Model::Serializable
|
|
69
|
+
attribute :bibdata, Bibdata
|
|
70
|
+
|
|
71
|
+
xml do
|
|
72
|
+
element "metanorma"
|
|
73
|
+
namespace Namespace
|
|
74
|
+
map_element "bibdata", to: :bibdata
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
RSpec.describe "Leptris custom Collection consolidation" do
|
|
80
|
+
around do |example|
|
|
81
|
+
original_adapter = Lutaml::Model::Config.xml_adapter
|
|
82
|
+
original_fast = Lutaml::Model::Config.instance.xml_plan_fast_path
|
|
83
|
+
Lutaml::Model::Config.xml_adapter_type = :leptris
|
|
84
|
+
example.run
|
|
85
|
+
ensure
|
|
86
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = original_fast
|
|
87
|
+
Lutaml::Model::Config.xml_adapter = original_adapter
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
let(:xml) do
|
|
91
|
+
File.read(File.expand_path("../../fixtures/metanorma_iec_title_consolidation.xml", __dir__))
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
[true, false].each do |fast|
|
|
95
|
+
it "organizes real nested title data with xml_plan_fast_path=#{fast}" do
|
|
96
|
+
expect(Lutaml::Xml::Leptris.plan_path_compatible?).to be(true)
|
|
97
|
+
|
|
98
|
+
Lutaml::Model::Config.instance.xml_plan_fast_path = fast
|
|
99
|
+
if fast
|
|
100
|
+
plan = Lutaml::Xml::Leptris::PlanCompiler.compile(
|
|
101
|
+
LeptrisConsolidationSpec::Document,
|
|
102
|
+
Lutaml::Model::Config.default_register,
|
|
103
|
+
)
|
|
104
|
+
expect(plan).not_to be_nil # Do not silently test an interpretive fallback.
|
|
105
|
+
allow(Lutaml::Xml::Leptris::PlanHydrator).to receive(:call).and_call_original
|
|
106
|
+
end
|
|
107
|
+
document = LeptrisConsolidationSpec::Document.from_xml(xml)
|
|
108
|
+
if fast
|
|
109
|
+
expect(Lutaml::Xml::Leptris::PlanHydrator).to have_received(:call)
|
|
110
|
+
.with(LeptrisConsolidationSpec::Bibdata, anything, anything, any_args)
|
|
111
|
+
end
|
|
112
|
+
titles = document.bibdata.titles
|
|
113
|
+
|
|
114
|
+
expect(titles.items.length).to eq(10)
|
|
115
|
+
expect(titles.per_language.size).to eq(2)
|
|
116
|
+
expect(titles.per_language.map(&:language)).to contain_exactly("en", "fr")
|
|
117
|
+
en = titles.per_language.find { |group| group.language == "en" }
|
|
118
|
+
fr = titles.per_language.find { |group| group.language == "fr" }
|
|
119
|
+
expect(en.full.value).to include("Cereals and pulses")
|
|
120
|
+
expect(en.part.value).to eq("Rice")
|
|
121
|
+
expect(fr.full.value).to include("Céréales et légumineuses")
|
|
122
|
+
expect(fr.part.value).to eq("Riz")
|
|
123
|
+
expect(fr.part_prefix.value).to eq("Partie\u00a01")
|
|
124
|
+
|
|
125
|
+
# Re-running post-processing replaces the organized view without
|
|
126
|
+
# duplicating groups or replacing the raw item collection.
|
|
127
|
+
original_items = titles.items.dup
|
|
128
|
+
Lutaml::Xml::CollectionConsolidation.call(document.bibdata, :default)
|
|
129
|
+
expect(titles.items).to eq(original_items)
|
|
130
|
+
expect(titles.per_language.size).to eq(2)
|
|
131
|
+
expect(titles.per_language.find { |group| group.language == "fr" }.part).to equal(fr.part)
|
|
132
|
+
|
|
133
|
+
reparsed = LeptrisConsolidationSpec::Document.from_xml(document.to_xml)
|
|
134
|
+
expect(reparsed.bibdata.titles.items.size).to eq(10)
|
|
135
|
+
expect(reparsed.bibdata.titles.per_language.size).to eq(2)
|
|
136
|
+
expect(reparsed.bibdata.titles.per_language.map { |group| group.part.value })
|
|
137
|
+
.to contain_exactly("Rice", "Riz")
|
|
138
|
+
end
|
|
139
|
+
end
|
|
140
|
+
end
|
|
@@ -279,4 +279,79 @@ RSpec.describe "runtime XSD class loading" do
|
|
|
279
279
|
expect(Lutaml::Model::Type::NmTokens.valid?("")).to be(false)
|
|
280
280
|
end
|
|
281
281
|
end
|
|
282
|
+
|
|
283
|
+
describe "register-isolated derivations (#1195)" do
|
|
284
|
+
let(:base_xsd) do
|
|
285
|
+
<<~XSD
|
|
286
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
287
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
288
|
+
<xs:complexType name="ImportedThing">
|
|
289
|
+
<xs:sequence>
|
|
290
|
+
<xs:element name="label" type="xs:string"/>
|
|
291
|
+
</xs:sequence>
|
|
292
|
+
</xs:complexType>
|
|
293
|
+
</xs:schema>
|
|
294
|
+
XSD
|
|
295
|
+
end
|
|
296
|
+
|
|
297
|
+
let(:main_xsd) do
|
|
298
|
+
<<~XSD
|
|
299
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
300
|
+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
|
|
301
|
+
<xs:import schemaLocation="base.xsd"/>
|
|
302
|
+
<xs:complexType name="MainDoc">
|
|
303
|
+
<xs:sequence>
|
|
304
|
+
<xs:element name="thing" type="ImportedThing"/>
|
|
305
|
+
</xs:sequence>
|
|
306
|
+
</xs:complexType>
|
|
307
|
+
<xs:element name="main" type="MainDoc"/>
|
|
308
|
+
</xs:schema>
|
|
309
|
+
XSD
|
|
310
|
+
end
|
|
311
|
+
|
|
312
|
+
let(:register_id) { :runtime_iso_reg }
|
|
313
|
+
|
|
314
|
+
after do
|
|
315
|
+
Lutaml::Model::GlobalRegister.unregister(register_id) if
|
|
316
|
+
Lutaml::Model::GlobalRegister.lookup(register_id)
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
it "parses instances through imported-schema types from the " \
|
|
320
|
+
"derivation's register, with the default register untouched" do
|
|
321
|
+
Dir.mktmpdir do |dir|
|
|
322
|
+
File.write(File.join(dir, "base.xsd"), base_xsd)
|
|
323
|
+
File.write(File.join(dir, "main.xsd"), main_xsd)
|
|
324
|
+
|
|
325
|
+
Lutaml::Model::Schema.from_xml(
|
|
326
|
+
main_xsd,
|
|
327
|
+
output_dir: File.join(dir, "reg_iso_models"),
|
|
328
|
+
load_classes: true,
|
|
329
|
+
module_namespace: "RegIsoRuntimeModels",
|
|
330
|
+
register_id: register_id.to_s,
|
|
331
|
+
location: File.join(dir, "main.xsd"),
|
|
332
|
+
)
|
|
333
|
+
|
|
334
|
+
parsed = RegIsoRuntimeModels::MainDoc.from_xml(
|
|
335
|
+
"<main><thing><label>hello</label></thing></main>",
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
expect(parsed.thing.label).to eq("hello")
|
|
339
|
+
expect(Lutaml::Model::Config.default_register).not_to eq(register_id)
|
|
340
|
+
end
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it "stamps the register through set_register_context, not " \
|
|
344
|
+
"instance_variable_set" do
|
|
345
|
+
entry = Lutaml::Model::Schema::CompiledOutput::Entry.new(
|
|
346
|
+
"ImportedThing", nil, :model
|
|
347
|
+
)
|
|
348
|
+
source = Lutaml::Model::Schema::RegistryGenerator.generate(
|
|
349
|
+
[entry], module_namespace: "ProbeRegNamespace",
|
|
350
|
+
register_id: register_id
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
expect(source).to include("set_register_context(:#{register_id})")
|
|
354
|
+
expect(source).not_to include("instance_variable_set")
|
|
355
|
+
end
|
|
356
|
+
end
|
|
282
357
|
end
|
|
@@ -83,6 +83,9 @@ RSpec.describe Lutaml::Yaml::Adapter::YeptrisAdapter do
|
|
|
83
83
|
{ "s" => "line1\nline2", "n" => nil },
|
|
84
84
|
{ "q" => "has: colon", "n" => nil },
|
|
85
85
|
{ "u" => "héllo wörld", "num" => "007", "f" => 1.5, "e" => "" },
|
|
86
|
+
# Under 80 characters, over 80 bytes: must not fold.
|
|
87
|
+
{ "cyr" => "процесс поглощения атмосферными газами " \
|
|
88
|
+
"электромагнитного излучения" },
|
|
86
89
|
{ "deep" => { "deeper" => [{ "x" => "y" }, [4, 5]] } },
|
|
87
90
|
{ "multi" => "para one\n\npara two", "dash" => "a - b - c",
|
|
88
91
|
"omitted" => nil },
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.8.
|
|
4
|
+
version: 0.8.182
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
@@ -789,6 +789,7 @@ files:
|
|
|
789
789
|
- lib/lutaml/xml/builder/oga.rb
|
|
790
790
|
- lib/lutaml/xml/builder/ox.rb
|
|
791
791
|
- lib/lutaml/xml/builder/rexml.rb
|
|
792
|
+
- lib/lutaml/xml/collection_consolidation.rb
|
|
792
793
|
- lib/lutaml/xml/configurable.rb
|
|
793
794
|
- lib/lutaml/xml/data_model.rb
|
|
794
795
|
- lib/lutaml/xml/decisions.rb
|
|
@@ -1042,6 +1043,7 @@ files:
|
|
|
1042
1043
|
- spec/fixtures/geolexica_v2_sample2.yaml
|
|
1043
1044
|
- spec/fixtures/liquid_templates/_ceramic.liquid
|
|
1044
1045
|
- spec/fixtures/liquid_templates/_ceramics_in_one.liquid
|
|
1046
|
+
- spec/fixtures/metanorma_iec_title_consolidation.xml
|
|
1045
1047
|
- spec/fixtures/person.rb
|
|
1046
1048
|
- spec/fixtures/sample_model.rb
|
|
1047
1049
|
- spec/fixtures/vase.rb
|
|
@@ -1831,6 +1833,7 @@ files:
|
|
|
1831
1833
|
- spec/lutaml/model/kv_flatten_memo_spec.rb
|
|
1832
1834
|
- spec/lutaml/model/late_attribute_declaration_spec.rb
|
|
1833
1835
|
- spec/lutaml/model/lazy_collection_spec.rb
|
|
1836
|
+
- spec/lutaml/model/leptris_consolidation_spec.rb
|
|
1834
1837
|
- spec/lutaml/model/liquefiable_lazy_spec.rb
|
|
1835
1838
|
- spec/lutaml/model/liquefiable_spec.rb
|
|
1836
1839
|
- spec/lutaml/model/liquid/indexed_access_spec.rb
|