lutaml-model 0.3.22 → 0.3.23
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/attribute.rb +1 -2
- data/lib/lutaml/model/serialize.rb +8 -7
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_mapping_rule.rb +2 -2
- 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: e7e401ce23a01b4dc80f709b71326b598cb9b9024b81d2a94f501bebf8112a14
|
4
|
+
data.tar.gz: 30534172ee835a9170e4335029702ec87ec4225c52e9e09566cb694fbd9c258d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce9d2be7aac031cba94181053fa59f19cb61ed6fafbdda177bec369a03fd92d53dcfc9caf43a34ebb439c7d69d2bf3f0db1a56a49e5cc34021a8fe4a0fc7fe25
|
7
|
+
data.tar.gz: 187168f579188ad1458013375fd5bacb6718dbb29d77994229c1c11fb14bcec5df8bae8bcfbe42dc3e57a5918c663741df7168338a2df36869562613aa06d149
|
@@ -200,11 +200,10 @@ module Lutaml
|
|
200
200
|
|
201
201
|
def cast(value, format, options = {})
|
202
202
|
value ||= [] if collection?
|
203
|
-
instance = options[:instance]
|
204
203
|
|
205
204
|
if value.is_a?(Array)
|
206
205
|
value.map do |v|
|
207
|
-
cast(v, format,
|
206
|
+
cast(v, format, options)
|
208
207
|
end
|
209
208
|
elsif type <= Serialize && value.is_a?(Hash)
|
210
209
|
type.apply_mappings(value, format, options)
|
@@ -35,7 +35,7 @@ module Lutaml
|
|
35
35
|
subclass.instance_variable_set(:@attributes,
|
36
36
|
Utils.deep_dup(@attributes))
|
37
37
|
subclass.instance_variable_set(:@mappings, Utils.deep_dup(@mappings))
|
38
|
-
subclass.instance_variable_set(:@model, subclass)
|
38
|
+
subclass.instance_variable_set(:@model, @model || subclass)
|
39
39
|
end
|
40
40
|
|
41
41
|
def model(klass = nil)
|
@@ -310,6 +310,7 @@ module Lutaml
|
|
310
310
|
def apply_xml_mapping(doc, instance, options = {})
|
311
311
|
return instance unless doc
|
312
312
|
|
313
|
+
options[:default_namespace] = mappings_for(:xml)&.namespace_uri if options[:default_namespace].nil?
|
313
314
|
mappings = mappings_for(:xml).mappings
|
314
315
|
|
315
316
|
if doc.is_a?(Array)
|
@@ -340,14 +341,14 @@ module Lutaml
|
|
340
341
|
doc.node.inner_xml
|
341
342
|
elsif rule.content_mapping?
|
342
343
|
doc["text"]
|
343
|
-
elsif doc.key_exist?(rule.namespaced_name)
|
344
|
-
doc.fetch(rule.namespaced_name)
|
344
|
+
elsif doc.key_exist?(rule.namespaced_name(options[:default_namespace]))
|
345
|
+
doc.fetch(rule.namespaced_name(options[:default_namespace]))
|
345
346
|
else
|
346
347
|
defaults_used << rule.to
|
347
348
|
rule.to_value_for(instance)
|
348
349
|
end
|
349
350
|
|
350
|
-
value = normalize_xml_value(value, rule)
|
351
|
+
value = normalize_xml_value(value, rule, options)
|
351
352
|
rule.deserialize(instance, value, attributes, self)
|
352
353
|
end
|
353
354
|
|
@@ -388,7 +389,7 @@ module Lutaml
|
|
388
389
|
instance
|
389
390
|
end
|
390
391
|
|
391
|
-
def normalize_xml_value(value, rule)
|
392
|
+
def normalize_xml_value(value, rule, options = {})
|
392
393
|
attr = attribute_for_rule(rule)
|
393
394
|
|
394
395
|
value = [value].compact if attr&.collection? && !value.is_a?(Array)
|
@@ -405,11 +406,11 @@ module Lutaml
|
|
405
406
|
|
406
407
|
return value unless cast_value?(attr, rule)
|
407
408
|
|
409
|
+
options.merge(caller_class: self, mixed_content: rule.mixed_content)
|
408
410
|
attr.cast(
|
409
411
|
value,
|
410
412
|
:xml,
|
411
|
-
|
412
|
-
mixed_content: rule.mixed_content,
|
413
|
+
options,
|
413
414
|
)
|
414
415
|
end
|
415
416
|
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -73,7 +73,7 @@ module Lutaml
|
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
76
|
-
def namespaced_name
|
76
|
+
def namespaced_name(parent_namespace = nil)
|
77
77
|
if name == "lang"
|
78
78
|
"#{prefix}:#{name}"
|
79
79
|
elsif namespace_set? || @attribute
|
@@ -81,7 +81,7 @@ module Lutaml
|
|
81
81
|
elsif default_namespace
|
82
82
|
"#{default_namespace}:#{name}"
|
83
83
|
else
|
84
|
-
name
|
84
|
+
[parent_namespace, name].compact.join(":")
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|