lutaml-model 0.7.6 → 0.7.7
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/lutaml/model/collection.rb +19 -2
- data/lib/lutaml/model/mapping/key_value_mapping.rb +17 -9
- data/lib/lutaml/model/mapping/key_value_mapping_rule.rb +1 -0
- data/lib/lutaml/model/register.rb +1 -1
- data/lib/lutaml/model/schema/shared_methods.rb +2 -2
- data/lib/lutaml/model/serialize.rb +4 -4
- data/lib/lutaml/model/version.rb +1 -1
- data/spec/lutaml/model/xml/root_mappings/nested_child_mappings_spec.rb +53 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 518cf7f42227fbdd75f25ed97d2107f0d0c575290ae2a21d5be323b70546cae4
|
4
|
+
data.tar.gz: 19f355abc4da8bff1ce95b06eba36aca987888325175aba9ab153998bcc8d68f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fb8b93ce570cc804f4f9d2f1562ac58dab5b76aa55b5d3b79d82a95eef6edc4c65752beeb7d6176878d4f765dbf40a3f63331b8b2b726363b7a5a506046d243
|
7
|
+
data.tar.gz: 10a50c4c30cf2034d3e394fd8526d00c220df5dcf216d8dd5fc19395858766254d8e8f835232404be2661d5821ebb05e82afad130b238d27aa224d5fc38855cd
|
@@ -4,6 +4,24 @@ module Lutaml
|
|
4
4
|
include Enumerable
|
5
5
|
|
6
6
|
class << self
|
7
|
+
INHERITED_ATTRIBUTES = %i[
|
8
|
+
instance_type
|
9
|
+
instance_name
|
10
|
+
order_by_field
|
11
|
+
order_direction
|
12
|
+
].freeze
|
13
|
+
|
14
|
+
def inherited(subclass)
|
15
|
+
super
|
16
|
+
|
17
|
+
INHERITED_ATTRIBUTES.each do |var|
|
18
|
+
subclass.instance_variable_set(
|
19
|
+
:"@#{var}",
|
20
|
+
instance_variable_get(:"@#{var}"),
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
7
25
|
attr_reader :instance_type,
|
8
26
|
:instance_name,
|
9
27
|
:order_by_field,
|
@@ -96,14 +114,13 @@ module Lutaml
|
|
96
114
|
items = [items].compact unless items.is_a?(Array)
|
97
115
|
|
98
116
|
register_object = Lutaml::Model::GlobalRegister.lookup(@__register)
|
99
|
-
type = register_object.
|
117
|
+
type = register_object.get_class(self.class.instance_type)
|
100
118
|
self.collection = items.map do |item|
|
101
119
|
if item.is_a?(type)
|
102
120
|
item
|
103
121
|
elsif type <= Lutaml::Model::Type::Value
|
104
122
|
type.cast(item)
|
105
123
|
else
|
106
|
-
item[:__register] = __register
|
107
124
|
type.new(item)
|
108
125
|
end
|
109
126
|
end
|
@@ -4,11 +4,11 @@ require_relative "key_value_mapping_rule"
|
|
4
4
|
module Lutaml
|
5
5
|
module Model
|
6
6
|
class KeyValueMapping < Mapping
|
7
|
-
attr_reader :
|
7
|
+
attr_reader :format, :key_mappings, :value_mappings
|
8
8
|
|
9
9
|
def initialize(format = nil)
|
10
10
|
super()
|
11
|
-
|
11
|
+
@mappings = {}
|
12
12
|
@format = format
|
13
13
|
end
|
14
14
|
|
@@ -49,7 +49,7 @@ module Lutaml
|
|
49
49
|
mapping_name = name_for_mapping(root_mappings, name)
|
50
50
|
validate!(mapping_name, to, with, render_nil, render_empty)
|
51
51
|
|
52
|
-
@mappings
|
52
|
+
@mappings[mapping_name] = KeyValueMappingRule.new(
|
53
53
|
mapping_name,
|
54
54
|
to: to,
|
55
55
|
render_nil: render_nil,
|
@@ -80,7 +80,7 @@ module Lutaml
|
|
80
80
|
)
|
81
81
|
@raw_mapping = true
|
82
82
|
validate!(Constants::RAW_MAPPING_KEY, to, with, render_nil, nil)
|
83
|
-
@mappings
|
83
|
+
@mappings[Constants::RAW_MAPPING_KEY] = KeyValueMappingRule.new(
|
84
84
|
Constants::RAW_MAPPING_KEY,
|
85
85
|
to: to,
|
86
86
|
render_nil: render_nil,
|
@@ -131,6 +131,14 @@ module Lutaml
|
|
131
131
|
name
|
132
132
|
end
|
133
133
|
|
134
|
+
def mappings
|
135
|
+
@mappings.values
|
136
|
+
end
|
137
|
+
|
138
|
+
def mappings_hash
|
139
|
+
@mappings
|
140
|
+
end
|
141
|
+
|
134
142
|
def validate!(key, to, with, render_nil, render_empty)
|
135
143
|
validate_mappings!(key)
|
136
144
|
validate_to_and_with_arguments!(key, to, with)
|
@@ -178,7 +186,7 @@ module Lutaml
|
|
178
186
|
|
179
187
|
def validate_mappings!(_type)
|
180
188
|
if (@raw_mapping && Utils.present?(@mappings)) ||
|
181
|
-
(!@raw_mapping &&
|
189
|
+
(!@raw_mapping && mappings.any?(&:raw_mapping?))
|
182
190
|
raise StandardError, "map_all is not allowed with other mappings"
|
183
191
|
end
|
184
192
|
end
|
@@ -190,11 +198,11 @@ module Lutaml
|
|
190
198
|
end
|
191
199
|
|
192
200
|
def duplicate_mappings
|
193
|
-
@mappings
|
201
|
+
Utils.deep_dup(@mappings)
|
194
202
|
end
|
195
203
|
|
196
204
|
def find_by_to(to)
|
197
|
-
|
205
|
+
mappings.find { |m| m.to.to_s == to.to_s }
|
198
206
|
end
|
199
207
|
|
200
208
|
def find_by_name(name)
|
@@ -202,11 +210,11 @@ module Lutaml
|
|
202
210
|
end
|
203
211
|
|
204
212
|
def polymorphic_mapping
|
205
|
-
|
213
|
+
mappings.find(&:polymorphic_mapping?)
|
206
214
|
end
|
207
215
|
|
208
216
|
def root_mapping
|
209
|
-
|
217
|
+
mappings.find(&:root_mapping?)
|
210
218
|
end
|
211
219
|
|
212
220
|
Lutaml::Model::Config::KEY_VALUE_FORMATS.each do |format|
|
@@ -28,7 +28,7 @@ module Lutaml
|
|
28
28
|
def get_class(klass_name)
|
29
29
|
expected_class = get_class_without_register(klass_name)
|
30
30
|
if !(expected_class < Lutaml::Model::Type::Value)
|
31
|
-
expected_class.class_variable_set(:@@
|
31
|
+
expected_class.class_variable_set(:@@__register, id)
|
32
32
|
end
|
33
33
|
expected_class
|
34
34
|
end
|
@@ -5,8 +5,8 @@ module Lutaml
|
|
5
5
|
module Schema
|
6
6
|
module SharedMethods
|
7
7
|
def extract_register_from(klass)
|
8
|
-
register = if klass.class_variable_defined?(:@@
|
9
|
-
klass.class_variable_get(:@@
|
8
|
+
register = if klass.class_variable_defined?(:@@__register)
|
9
|
+
klass.class_variable_get(:@@__register)
|
10
10
|
end
|
11
11
|
|
12
12
|
case register
|
@@ -211,14 +211,14 @@ module Lutaml
|
|
211
211
|
@mappings[format].merge_mapping_elements(mapping)
|
212
212
|
@mappings[format].merge_elements_sequence(mapping)
|
213
213
|
else
|
214
|
-
@mappings[format].
|
214
|
+
@mappings[format].mappings_hash.merge!(mapping.mappings_hash)
|
215
215
|
end
|
216
216
|
end
|
217
217
|
end
|
218
218
|
|
219
219
|
def handle_key_value_mappings(mapping, format)
|
220
220
|
@mappings[format] ||= KeyValueMapping.new
|
221
|
-
@mappings[format].
|
221
|
+
@mappings[format].mappings_hash.merge!(mapping.mappings_hash)
|
222
222
|
end
|
223
223
|
|
224
224
|
def import_model(model)
|
@@ -497,8 +497,8 @@ module Lutaml
|
|
497
497
|
def extract_register_id(register)
|
498
498
|
if register
|
499
499
|
register.is_a?(Lutaml::Model::Register) ? register.id : register
|
500
|
-
elsif class_variable_defined?(:@@
|
501
|
-
class_variable_get(:@@
|
500
|
+
elsif class_variable_defined?(:@@__register)
|
501
|
+
class_variable_get(:@@__register)
|
502
502
|
else
|
503
503
|
Lutaml::Model::Config.default_register
|
504
504
|
end
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -47,6 +47,10 @@ module NestedChildMappingsSpec
|
|
47
47
|
}
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
class ManifestResponseWrap < ManifestResponse
|
52
|
+
# This class confirms the successful inhertiance of the `Collection` attribute.
|
53
|
+
end
|
50
54
|
end
|
51
55
|
|
52
56
|
RSpec.describe "NestedChildMappingsSpec" do
|
@@ -90,10 +94,54 @@ RSpec.describe "NestedChildMappingsSpec" do
|
|
90
94
|
YAML
|
91
95
|
end
|
92
96
|
|
97
|
+
let(:wrapped_yaml) do
|
98
|
+
<<~YAML
|
99
|
+
---
|
100
|
+
Yu Gothic:
|
101
|
+
Bold:
|
102
|
+
full_name: Yu Gothic Bold
|
103
|
+
paths:
|
104
|
+
- "/Applications/Microsoft Excel.app/Contents/Resources/DFonts/YuGothB.ttc"
|
105
|
+
- "/Applications/Microsoft OneNote.app/Contents/Resources/DFonts/YuGothB.ttc"
|
106
|
+
- "/Applications/Microsoft Outlook.app/Contents/Resources/DFonts/YuGothB.ttc"
|
107
|
+
- "/Applications/Microsoft PowerPoint.app/Contents/Resources/DFonts/YuGothB.ttc"
|
108
|
+
- "/Applications/Microsoft Word.app/Contents/Resources/DFonts/YuGothB.ttc"
|
109
|
+
Regular:
|
110
|
+
full_name: Yu Gothic Regular
|
111
|
+
paths:
|
112
|
+
- "/Applications/Microsoft Excel.app/Contents/Resources/DFonts/YuGothR.ttc"
|
113
|
+
- "/Applications/Microsoft OneNote.app/Contents/Resources/DFonts/YuGothR.ttc"
|
114
|
+
- "/Applications/Microsoft Outlook.app/Contents/Resources/DFonts/YuGothR.ttc"
|
115
|
+
- "/Applications/Microsoft PowerPoint.app/Contents/Resources/DFonts/YuGothR.ttc"
|
116
|
+
- "/Applications/Microsoft Word.app/Contents/Resources/DFonts/YuGothR.ttc"
|
117
|
+
Noto Sans Condensed:
|
118
|
+
Regular:
|
119
|
+
full_name: Noto Sans Condensed
|
120
|
+
paths:
|
121
|
+
- "/Users/foo/.fontist/fonts/NotoSans-Condensed.ttf"
|
122
|
+
Bold:
|
123
|
+
full_name: Noto Sans Condensed Bold
|
124
|
+
paths:
|
125
|
+
- "/Users/foo/.fontist/fonts/NotoSans-CondensedBold.ttf"
|
126
|
+
Bold Italic:
|
127
|
+
full_name: Noto Sans Condensed Bold Italic
|
128
|
+
paths:
|
129
|
+
- "/Users/foo/.fontist/fonts/NotoSans-CondensedBoldItalic.ttf"
|
130
|
+
Italic:
|
131
|
+
full_name: Noto Sans Condensed Italic
|
132
|
+
paths:
|
133
|
+
- "/Users/foo/.fontist/fonts/NotoSans-CondensedItalic.ttf"
|
134
|
+
YAML
|
135
|
+
end
|
136
|
+
|
93
137
|
let(:parsed_yaml) do
|
94
138
|
NestedChildMappingsSpec::ManifestResponse.from_yaml(yaml)
|
95
139
|
end
|
96
140
|
|
141
|
+
let(:wrap_parsed_yaml) do
|
142
|
+
NestedChildMappingsSpec::ManifestResponseWrap.from_yaml(wrapped_yaml)
|
143
|
+
end
|
144
|
+
|
97
145
|
let(:expected_fonts) do
|
98
146
|
NestedChildMappingsSpec::ManifestResponse.new(
|
99
147
|
[
|
@@ -161,4 +209,9 @@ RSpec.describe "NestedChildMappingsSpec" do
|
|
161
209
|
expected_yaml = parsed_yaml.to_yaml
|
162
210
|
expect(expected_yaml).to eq(yaml)
|
163
211
|
end
|
212
|
+
|
213
|
+
it "round trips nested child mappings correctly with Wrap class" do
|
214
|
+
expected_yaml = wrap_parsed_yaml.to_yaml
|
215
|
+
expect(expected_yaml).to eq(yaml)
|
216
|
+
end
|
164
217
|
end
|