lutaml-model 0.6.0 → 0.6.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 448150f0306f0357d896344e44f6f3cfe57fa301d4ad17d3479cead4dc6bcbfe
|
4
|
+
data.tar.gz: e86a83e06ea4b49b8d0a0cffb3235fb02c683bff4fdfa9e5ffebc3604b7cb1bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3e05c87251d2f2b73f6a0f27c87e24535c77e2fbf01d95375bfb0f107e78dab77deeb837010df3ea8f8bc9e98284e0b660381776d4d6ef686616d40f227d8cbf
|
7
|
+
data.tar.gz: 895641b33bf3ab077d95551c4879564b689333bc397e5ff4e820e73e96cae36ff3283e76b82c67406371898f9a36313d8ede2ed8b7675729a9dd3111f4079627
|
@@ -248,13 +248,12 @@ module Lutaml
|
|
248
248
|
end
|
249
249
|
|
250
250
|
def cast(value, format, options = {})
|
251
|
-
value
|
251
|
+
return value if type <= Serialize && value.is_a?(type.model)
|
252
252
|
|
253
|
+
value ||= [] if collection?
|
253
254
|
if value.is_a?(Array)
|
254
|
-
value.map
|
255
|
-
|
256
|
-
end
|
257
|
-
elsif type <= Serialize && value.is_a?(Hash)
|
255
|
+
value.map { |v| cast(v, format, options) }
|
256
|
+
elsif type <= Serialize && (value.is_a?(Hash) || value.is_a?(Lutaml::Model::XmlAdapter::XmlElement))
|
258
257
|
type.apply_mappings(value, format, options)
|
259
258
|
elsif !value.nil? && !value.is_a?(type)
|
260
259
|
type.send(:"from_#{format}", value)
|
@@ -493,8 +493,9 @@ module Lutaml
|
|
493
493
|
|
494
494
|
raise Lutaml::Model::CollectionTrueMissingError(self, option[:caller_class]) if doc.is_a?(Array)
|
495
495
|
|
496
|
+
doc_order = doc.root.order
|
496
497
|
if instance.respond_to?(:ordered=)
|
497
|
-
instance.element_order =
|
498
|
+
instance.element_order = doc_order
|
498
499
|
instance.ordered = mappings_for(:xml).ordered? || options[:ordered]
|
499
500
|
instance.mixed = mappings_for(:xml).mixed_content? || options[:mixed_content]
|
500
501
|
end
|
@@ -512,7 +513,7 @@ module Lutaml
|
|
512
513
|
end
|
513
514
|
|
514
515
|
defaults_used = []
|
515
|
-
validate_sequence!(
|
516
|
+
validate_sequence!(doc_order)
|
516
517
|
|
517
518
|
mappings.each do |rule|
|
518
519
|
raise "Attribute '#{rule.to}' not found in #{self}" unless valid_rule?(rule)
|
@@ -534,9 +535,7 @@ module Lutaml
|
|
534
535
|
rule.deserialize(instance, value, attributes, self)
|
535
536
|
end
|
536
537
|
|
537
|
-
defaults_used.each
|
538
|
-
instance.using_default_for(attribute_name)
|
539
|
-
end
|
538
|
+
defaults_used.each { |attr_name| instance.using_default_for(attr_name) }
|
540
539
|
|
541
540
|
instance
|
542
541
|
end
|
@@ -548,9 +547,8 @@ module Lutaml
|
|
548
547
|
doc.root.find_attribute_value(rule_names)
|
549
548
|
else
|
550
549
|
attr = attribute_for_rule(rule)
|
551
|
-
|
552
550
|
children = doc.children.select do |child|
|
553
|
-
rule_names.include?(child.namespaced_name)
|
551
|
+
rule_names.include?(child.namespaced_name) && !child.text?
|
554
552
|
end
|
555
553
|
|
556
554
|
if rule.using_custom_methods? || attr.type == Lutaml::Model::Type::Hash
|
@@ -570,7 +568,7 @@ module Lutaml
|
|
570
568
|
|
571
569
|
values = children.map do |child|
|
572
570
|
if !rule.using_custom_methods? && attr.type <= Serialize
|
573
|
-
attr.
|
571
|
+
attr.cast(child, :xml, options.except(:mappings))
|
574
572
|
elsif attr.raw?
|
575
573
|
inner_xml_of(child)
|
576
574
|
else
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -5,13 +5,53 @@ class CustomModelChild
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class CustomModelParent
|
8
|
-
attr_accessor :first_name, :middle_name, :last_name, :child_mapper
|
8
|
+
attr_accessor :first_name, :middle_name, :last_name, :child_mapper, :math
|
9
9
|
|
10
10
|
def name
|
11
11
|
"#{first_name} #{last_name}"
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
class GenericFormulaClass
|
16
|
+
attr_accessor :value
|
17
|
+
end
|
18
|
+
|
19
|
+
class Mi < Lutaml::Model::Serializable
|
20
|
+
model GenericFormulaClass
|
21
|
+
|
22
|
+
attribute :value, :string
|
23
|
+
|
24
|
+
xml do
|
25
|
+
root "mi"
|
26
|
+
|
27
|
+
map_content to: :value
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class Mstyle < Lutaml::Model::Serializable
|
32
|
+
model GenericFormulaClass
|
33
|
+
|
34
|
+
attribute :value, Mi, collection: true
|
35
|
+
|
36
|
+
xml do
|
37
|
+
root "mstyle"
|
38
|
+
|
39
|
+
map_element :mi, to: :value
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class MmlMath < Lutaml::Model::Serializable
|
44
|
+
model GenericFormulaClass
|
45
|
+
|
46
|
+
attribute :value, Mstyle, collection: true
|
47
|
+
|
48
|
+
xml do
|
49
|
+
root "math"
|
50
|
+
|
51
|
+
map_element :mstyle, to: :value
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
15
55
|
class CustomModelChildMapper < Lutaml::Model::Serializable
|
16
56
|
model CustomModelChild
|
17
57
|
|
@@ -31,6 +71,7 @@ class CustomModelParentMapper < Lutaml::Model::Serializable
|
|
31
71
|
attribute :middle_name, Lutaml::Model::Type::String
|
32
72
|
attribute :last_name, Lutaml::Model::Type::String
|
33
73
|
attribute :child_mapper, CustomModelChildMapper
|
74
|
+
attribute :math, MmlMath
|
34
75
|
|
35
76
|
xml do
|
36
77
|
map_element :first_name, to: :first_name
|
@@ -38,6 +79,7 @@ class CustomModelParentMapper < Lutaml::Model::Serializable
|
|
38
79
|
map_element :last_name, to: :last_name
|
39
80
|
map_element :CustomModelChild,
|
40
81
|
with: { to: :child_to_xml, from: :child_from_xml }
|
82
|
+
map_element :math, to: :math
|
41
83
|
end
|
42
84
|
|
43
85
|
def child_to_xml(model, parent, doc)
|
@@ -317,6 +359,11 @@ RSpec.describe "CustomModel" do
|
|
317
359
|
<street>Oxford Street</street>
|
318
360
|
<city>London</city>
|
319
361
|
</CustomModelChild>
|
362
|
+
<math>
|
363
|
+
<mstyle>
|
364
|
+
<mi>Math</mi>
|
365
|
+
</mstyle>
|
366
|
+
</math>
|
320
367
|
</CustomModelParent>
|
321
368
|
XML
|
322
369
|
end
|
@@ -333,6 +380,7 @@ RSpec.describe "CustomModel" do
|
|
333
380
|
expect(instance.child_mapper.class).to eq(child_model)
|
334
381
|
expect(instance.child_mapper.street).to eq("Oxford Street")
|
335
382
|
expect(instance.child_mapper.city).to eq("London")
|
383
|
+
expect(instance.math.value.first.value.first.value).to eq("Math")
|
336
384
|
end
|
337
385
|
end
|
338
386
|
|
@@ -57,6 +57,7 @@ module XmlMapping
|
|
57
57
|
class Address < Lutaml::Model::Serializable
|
58
58
|
attribute :street, ::Lutaml::Model::Type::String, raw: true
|
59
59
|
attribute :city, :string, raw: true
|
60
|
+
attribute :text, :string
|
60
61
|
attribute :address, Address
|
61
62
|
|
62
63
|
xml do
|
@@ -64,6 +65,7 @@ module XmlMapping
|
|
64
65
|
|
65
66
|
map_element "street", to: :street
|
66
67
|
map_element "city", to: :city
|
68
|
+
map_element "text", to: :text
|
67
69
|
end
|
68
70
|
end
|
69
71
|
|
@@ -838,6 +840,7 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
838
840
|
<p>adf</p>
|
839
841
|
</street>
|
840
842
|
<city><a>M</a></city>
|
843
|
+
<text>Building near ABC</text>
|
841
844
|
</address>
|
842
845
|
</person>
|
843
846
|
XML
|
@@ -859,6 +862,27 @@ RSpec.describe Lutaml::Model::XmlMapping do
|
|
859
862
|
end
|
860
863
|
end
|
861
864
|
|
865
|
+
context "with element named `text`" do
|
866
|
+
let(:input_xml) do
|
867
|
+
<<~XML
|
868
|
+
<address>
|
869
|
+
<street>
|
870
|
+
<a>N</a>
|
871
|
+
<p>adf</p>
|
872
|
+
</street>
|
873
|
+
<city><a>M</a></city>
|
874
|
+
<text>Building near ABC</text>
|
875
|
+
</address>
|
876
|
+
XML
|
877
|
+
end
|
878
|
+
|
879
|
+
let(:model) { XmlMapping::Address.from_xml(input_xml) }
|
880
|
+
|
881
|
+
it "expect to contain raw xml" do
|
882
|
+
expect(model.text).to eq("Building near ABC")
|
883
|
+
end
|
884
|
+
end
|
885
|
+
|
862
886
|
context "with content mapping" do
|
863
887
|
let(:xml_data) { "<i>my text <b>bold</b> is in italics</i>" }
|
864
888
|
let(:italic) { Italic.from_xml(xml_data) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lutaml-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
11
|
+
date: 2025-02-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base64
|