lutaml-model 0.3.8 → 0.3.9
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/.rubocop_todo.yml +17 -26
- data/README.adoc +78 -77
- data/lib/lutaml/model/serialize.rb +4 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/ox.rb +13 -3
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +3 -0
- data/lib/lutaml/model/xml_adapter/xml_document.rb +9 -7
- data/lib/lutaml/model/xml_mapping.rb +1 -3
- data/lutaml-model.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 12f6b0d44c864c56f2573bae9a712485e0b266120fe53f342671b8cb144ce022
|
|
4
|
+
data.tar.gz: 3facbc5cc6ef8149f1628415f3d511c2e010de28f8ab5968f2e436eb6aa41b39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0157ca6aa7a9e0e0368fd1da623068670d033a54385b91aa45082412512f5ee1643d72da168d5b68fdef531034f49363417dbfce31c4b47452c8f1d0136d839d
|
|
7
|
+
data.tar.gz: cf6c69e91f9eb13275a845ee4253809cc60599527a26f28d13942fa26b10ce65bfbc6a6fed8fbc946a721a1d07edd8b98289447c668f7d8cba6dc3cd001bc85b
|
data/.rubocop_todo.yml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# This configuration was generated by
|
|
2
2
|
# `rubocop --auto-gen-config`
|
|
3
|
-
# on 2024-
|
|
3
|
+
# on 2024-09-04 07:55:32 UTC using RuboCop version 1.66.0.
|
|
4
4
|
# The point is for the user to remove these configuration records
|
|
5
5
|
# one by one as the offenses are removed from the code base.
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
|
@@ -14,27 +14,14 @@ Gemspec/RequireMFA:
|
|
|
14
14
|
Exclude:
|
|
15
15
|
- 'lutaml-model.gemspec'
|
|
16
16
|
|
|
17
|
-
# Offense count:
|
|
17
|
+
# Offense count: 62
|
|
18
18
|
# This cop supports safe autocorrection (--autocorrect).
|
|
19
19
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
|
20
20
|
# URISchemes: http, https
|
|
21
21
|
Layout/LineLength:
|
|
22
|
-
|
|
23
|
-
- 'lib/lutaml/model/cli.rb'
|
|
24
|
-
- 'lib/lutaml/model/comparable_model.rb'
|
|
25
|
-
- 'lib/lutaml/model/serialize.rb'
|
|
26
|
-
- 'lib/lutaml/model/type.rb'
|
|
27
|
-
- 'lib/lutaml/model/utils.rb'
|
|
28
|
-
- 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
|
|
29
|
-
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
|
30
|
-
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
|
31
|
-
- 'spec/lutaml/model/comparable_model_spec.rb'
|
|
32
|
-
- 'spec/lutaml/model/custom_serialization_spec.rb'
|
|
33
|
-
- 'spec/lutaml/model/delegation_spec.rb'
|
|
34
|
-
- 'spec/lutaml/model/schema/json_schema_spec.rb'
|
|
35
|
-
- 'spec/lutaml/model/serializable_spec.rb'
|
|
22
|
+
Enabled: false
|
|
36
23
|
|
|
37
|
-
# Offense count:
|
|
24
|
+
# Offense count: 10
|
|
38
25
|
# Configuration parameters: AllowedMethods.
|
|
39
26
|
# AllowedMethods: enums
|
|
40
27
|
Lint/ConstantDefinitionInBlock:
|
|
@@ -43,8 +30,9 @@ Lint/ConstantDefinitionInBlock:
|
|
|
43
30
|
- 'spec/lutaml/model/schema/relaxng_schema_spec.rb'
|
|
44
31
|
- 'spec/lutaml/model/schema/xsd_schema_spec.rb'
|
|
45
32
|
- 'spec/lutaml/model/schema/yaml_schema_spec.rb'
|
|
33
|
+
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
|
46
34
|
|
|
47
|
-
# Offense count:
|
|
35
|
+
# Offense count: 29
|
|
48
36
|
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
|
|
49
37
|
Metrics/AbcSize:
|
|
50
38
|
Exclude:
|
|
@@ -57,11 +45,11 @@ Metrics/AbcSize:
|
|
|
57
45
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
|
58
46
|
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
|
59
47
|
|
|
60
|
-
# Offense count:
|
|
48
|
+
# Offense count: 6
|
|
61
49
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
|
62
50
|
# AllowedMethods: refine
|
|
63
51
|
Metrics/BlockLength:
|
|
64
|
-
Max:
|
|
52
|
+
Max: 42
|
|
65
53
|
|
|
66
54
|
# Offense count: 22
|
|
67
55
|
# Configuration parameters: AllowedMethods, AllowedPatterns, Max.
|
|
@@ -96,7 +84,7 @@ Metrics/PerceivedComplexity:
|
|
|
96
84
|
- 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
|
|
97
85
|
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
|
98
86
|
|
|
99
|
-
# Offense count:
|
|
87
|
+
# Offense count: 7
|
|
100
88
|
# Configuration parameters: Prefixes, AllowedPatterns.
|
|
101
89
|
# Prefixes: when, with, without
|
|
102
90
|
RSpec/ContextWording:
|
|
@@ -104,8 +92,9 @@ RSpec/ContextWording:
|
|
|
104
92
|
- 'spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb'
|
|
105
93
|
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
|
106
94
|
- 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
|
|
95
|
+
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
|
107
96
|
|
|
108
|
-
# Offense count:
|
|
97
|
+
# Offense count: 86
|
|
109
98
|
# Configuration parameters: CountAsOne.
|
|
110
99
|
RSpec/ExampleLength:
|
|
111
100
|
Max: 57
|
|
@@ -116,13 +105,14 @@ RSpec/IndexedLet:
|
|
|
116
105
|
Exclude:
|
|
117
106
|
- 'spec/address_spec.rb'
|
|
118
107
|
|
|
119
|
-
# Offense count:
|
|
108
|
+
# Offense count: 18
|
|
120
109
|
RSpec/LeakyConstantDeclaration:
|
|
121
110
|
Exclude:
|
|
122
111
|
- 'spec/lutaml/model/schema/json_schema_spec.rb'
|
|
123
112
|
- 'spec/lutaml/model/schema/relaxng_schema_spec.rb'
|
|
124
113
|
- 'spec/lutaml/model/schema/xsd_schema_spec.rb'
|
|
125
114
|
- 'spec/lutaml/model/schema/yaml_schema_spec.rb'
|
|
115
|
+
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
|
126
116
|
|
|
127
117
|
# Offense count: 4
|
|
128
118
|
RSpec/MultipleDescribes:
|
|
@@ -132,18 +122,19 @@ RSpec/MultipleDescribes:
|
|
|
132
122
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
|
133
123
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
|
134
124
|
|
|
135
|
-
# Offense count:
|
|
125
|
+
# Offense count: 75
|
|
136
126
|
RSpec/MultipleExpectations:
|
|
137
|
-
Max:
|
|
127
|
+
Max: 11
|
|
138
128
|
|
|
139
129
|
# Offense count: 11
|
|
140
130
|
# Configuration parameters: AllowSubject.
|
|
141
131
|
RSpec/MultipleMemoizedHelpers:
|
|
142
132
|
Max: 9
|
|
143
133
|
|
|
144
|
-
# Offense count:
|
|
134
|
+
# Offense count: 4
|
|
145
135
|
RSpec/PendingWithoutReason:
|
|
146
136
|
Exclude:
|
|
137
|
+
- 'spec/lutaml/model/mixed_content_spec.rb'
|
|
147
138
|
- 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
|
|
148
139
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
|
149
140
|
- 'spec/lutaml/model/xml_adapter_spec.rb'
|
data/README.adoc
CHANGED
|
@@ -652,6 +652,7 @@ end
|
|
|
652
652
|
|
|
653
653
|
==== Namespaces
|
|
654
654
|
|
|
655
|
+
[[root-namespace]]
|
|
655
656
|
===== Namespace at root
|
|
656
657
|
|
|
657
658
|
The `namespace` method in the `xml` block sets the namespace for the root
|
|
@@ -659,6 +660,7 @@ element.
|
|
|
659
660
|
|
|
660
661
|
Syntax:
|
|
661
662
|
|
|
663
|
+
.Setting default namespace at the root element
|
|
662
664
|
[source,ruby]
|
|
663
665
|
----
|
|
664
666
|
xml do
|
|
@@ -666,6 +668,15 @@ xml do
|
|
|
666
668
|
end
|
|
667
669
|
----
|
|
668
670
|
|
|
671
|
+
.Setting a prefixed namespace at the root element
|
|
672
|
+
[source,ruby]
|
|
673
|
+
----
|
|
674
|
+
xml do
|
|
675
|
+
namespace 'http://example.com/namespace', 'prefix'
|
|
676
|
+
end
|
|
677
|
+
----
|
|
678
|
+
|
|
679
|
+
|
|
669
680
|
.Using the `namespace` method to set the namespace for the root element
|
|
670
681
|
[example]
|
|
671
682
|
====
|
|
@@ -698,10 +709,43 @@ end
|
|
|
698
709
|
----
|
|
699
710
|
====
|
|
700
711
|
|
|
712
|
+
.Using the `namespace` method to set a prefixed namespace for the root element
|
|
713
|
+
[example]
|
|
714
|
+
====
|
|
715
|
+
[source,ruby]
|
|
716
|
+
----
|
|
717
|
+
class Ceramic < Lutaml::Model::Serializable
|
|
718
|
+
attribute :type, :string
|
|
719
|
+
attribute :glaze, :string
|
|
720
|
+
|
|
721
|
+
xml do
|
|
722
|
+
root 'Ceramic'
|
|
723
|
+
namespace 'http://example.com/ceramic', 'cer'
|
|
724
|
+
map_element 'Type', to: :type
|
|
725
|
+
map_element 'Glaze', to: :glaze
|
|
726
|
+
end
|
|
727
|
+
end
|
|
728
|
+
----
|
|
729
|
+
|
|
730
|
+
[source,xml]
|
|
731
|
+
----
|
|
732
|
+
<cer:Ceramic xmlns='http://example.com/ceramic'><cer:Type>Porcelain</cer:Type><cer:Glaze>Clear</cer:Glaze></cer:Ceramic>
|
|
733
|
+
----
|
|
734
|
+
|
|
735
|
+
[source,ruby]
|
|
736
|
+
----
|
|
737
|
+
> Ceramic.from_xml(xml_file)
|
|
738
|
+
> #<Ceramic:0x0000000104ac7240 @type="Porcelain", @glaze="Clear">
|
|
739
|
+
> Ceramic.new(type: "Porcelain", glaze: "Clear").to_xml
|
|
740
|
+
> #<cer:Ceramic xmlns="http://example.com/ceramic"><cer:Type>Porcelain</cer:Type><cer:Glaze>Clear</cer:Glaze></cer:Ceramic>
|
|
741
|
+
----
|
|
742
|
+
====
|
|
743
|
+
|
|
744
|
+
|
|
701
745
|
===== Namespace on attribute
|
|
702
746
|
|
|
703
|
-
If the namespace is defined on
|
|
704
|
-
priority over the one defined in the class.
|
|
747
|
+
If the namespace is defined on a model attribute that already has a namespace,
|
|
748
|
+
the mapped namespace will be given priority over the one defined in the class.
|
|
705
749
|
|
|
706
750
|
Syntax:
|
|
707
751
|
|
|
@@ -725,6 +769,19 @@ In this example, `glz` will be used for `Glaze` if it is added inside the
|
|
|
725
769
|
|
|
726
770
|
[source,ruby]
|
|
727
771
|
----
|
|
772
|
+
class Ceramic < Lutaml::Model::Serializable
|
|
773
|
+
attribute :type, :string
|
|
774
|
+
attribute :glaze, Glaze
|
|
775
|
+
|
|
776
|
+
xml do
|
|
777
|
+
root 'Ceramic'
|
|
778
|
+
namespace 'http://example.com/ceramic'
|
|
779
|
+
|
|
780
|
+
map_element 'Type', to: :type
|
|
781
|
+
map_element 'Glaze', to: :glaze, namespace: 'http://example.com/glaze', prefix: "glz"
|
|
782
|
+
end
|
|
783
|
+
end
|
|
784
|
+
|
|
728
785
|
class Glaze < Lutaml::Model::Serializable
|
|
729
786
|
attribute :color, :string
|
|
730
787
|
attribute :temperature, :integer
|
|
@@ -737,18 +794,6 @@ class Glaze < Lutaml::Model::Serializable
|
|
|
737
794
|
map_element 'temperature', to: :temperature
|
|
738
795
|
end
|
|
739
796
|
end
|
|
740
|
-
|
|
741
|
-
class Ceramic < Lutaml::Model::Serializable
|
|
742
|
-
attribute :type, :string
|
|
743
|
-
attribute :glaze, Glaze
|
|
744
|
-
|
|
745
|
-
xml do
|
|
746
|
-
root 'Ceramic'
|
|
747
|
-
map_element 'Type', to: :type
|
|
748
|
-
map_element 'Glaze', to: :glaze, namespace: 'http://example.com/glaze', prefix: "glz"
|
|
749
|
-
map_attribute 'xmlns', to: :namespace, namespace: 'http://example.com/ceramic'
|
|
750
|
-
end
|
|
751
|
-
end
|
|
752
797
|
----
|
|
753
798
|
|
|
754
799
|
[source,xml]
|
|
@@ -764,6 +809,11 @@ end
|
|
|
764
809
|
|
|
765
810
|
[source,ruby]
|
|
766
811
|
----
|
|
812
|
+
> # Using the original Glaze class namespace
|
|
813
|
+
> Glaze.new(color: "Clear", temperature: 1050).to_xml
|
|
814
|
+
> #<glaze:Glaze xmlns="http://example.com/old_glaze"><color>Clear</color><temperature>1050</temperature></glaze:Glaze>
|
|
815
|
+
|
|
816
|
+
> # Using the Ceramic class namespace for Glaze
|
|
767
817
|
> Ceramic.from_xml(xml_file)
|
|
768
818
|
> #<Ceramic:0x0000000104ac7240 @type="Porcelain", @glaze=#<Glaze:0x0000000104ac7240 @color="Clear", @temperature=1050>>
|
|
769
819
|
> Ceramic.new(type: "Porcelain", glaze: Glaze.new(color: "Clear", temperature: 1050)).to_xml
|
|
@@ -800,7 +850,7 @@ class Ceramic < Lutaml::Model::Serializable
|
|
|
800
850
|
|
|
801
851
|
xml do
|
|
802
852
|
root 'Ceramic'
|
|
803
|
-
namespace 'http://example.com/ceramic',
|
|
853
|
+
namespace 'http://example.com/ceramic', 'cera'
|
|
804
854
|
map_element 'Type', to: :type, namespace: :inherit
|
|
805
855
|
map_element 'Glaze', to: :glaze
|
|
806
856
|
map_attribute 'color', to: :color, namespace: 'http://example.com/color', prefix: 'clr'
|
|
@@ -810,13 +860,13 @@ end
|
|
|
810
860
|
|
|
811
861
|
[source,xml]
|
|
812
862
|
----
|
|
813
|
-
<Ceramic
|
|
863
|
+
<cera:Ceramic
|
|
814
864
|
xmlns:cera='http://example.com/ceramic'
|
|
815
865
|
xmlns:clr='http://example.com/color'
|
|
816
866
|
clr:color="navy-blue">
|
|
817
867
|
<cera:Type>Porcelain</cera:Type>
|
|
818
868
|
<Glaze>Clear</Glaze>
|
|
819
|
-
</Ceramic>
|
|
869
|
+
</cera:Ceramic>
|
|
820
870
|
----
|
|
821
871
|
|
|
822
872
|
[source,ruby]
|
|
@@ -824,20 +874,18 @@ end
|
|
|
824
874
|
> Ceramic.from_xml(xml_file)
|
|
825
875
|
> #<Ceramic:0x0000000104ac7240 @type="Porcelain", @glaze="Clear", @color="navy-blue">
|
|
826
876
|
> Ceramic.new(type: "Porcelain", glaze: "Clear", color: "navy-blue").to_xml
|
|
827
|
-
> #<Ceramic xmlns:cera="http://example.com/ceramic"
|
|
877
|
+
> #<cera:Ceramic xmlns:cera="http://example.com/ceramic"
|
|
828
878
|
# xmlns:clr='http://example.com/color'
|
|
829
879
|
# clr:color="navy-blue">
|
|
830
880
|
# <cera:Type>Porcelain</cera:Type>
|
|
831
881
|
# <Glaze>Clear</Glaze>
|
|
832
|
-
# </Ceramic>
|
|
882
|
+
# </cera:Ceramic>
|
|
833
883
|
----
|
|
834
884
|
====
|
|
835
885
|
|
|
836
886
|
[[mixed-content]]
|
|
837
887
|
==== Mixed content
|
|
838
888
|
|
|
839
|
-
===== General
|
|
840
|
-
|
|
841
889
|
In XML there can be tags that contain content mixed with other tags and where
|
|
842
890
|
whitespace is significant, such as to represent rich text.
|
|
843
891
|
|
|
@@ -857,9 +905,8 @@ To map this to Lutaml::Model we can use the `mixed` option in either way:
|
|
|
857
905
|
NOTE: This feature is not supported by Shale.
|
|
858
906
|
|
|
859
907
|
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
This will always treat the content of the element itself as mixed content.
|
|
908
|
+
To specify mixed content, the `mixed: true` option needs to be set at the
|
|
909
|
+
`xml` block's `root` method.
|
|
863
910
|
|
|
864
911
|
Syntax:
|
|
865
912
|
|
|
@@ -876,7 +923,7 @@ end
|
|
|
876
923
|
[source,ruby]
|
|
877
924
|
----
|
|
878
925
|
class Paragraph < Lutaml::Model::Serializable
|
|
879
|
-
attribute :bold, :string
|
|
926
|
+
attribute :bold, :string, collection: true # allows multiple bold tags
|
|
880
927
|
attribute :italic, :string
|
|
881
928
|
|
|
882
929
|
xml do
|
|
@@ -900,57 +947,6 @@ end
|
|
|
900
947
|
TODO: How to create mixed content from `#new`?
|
|
901
948
|
|
|
902
949
|
|
|
903
|
-
===== Specifying the `mixed` option when referencing a model
|
|
904
|
-
|
|
905
|
-
This will only treat the content of the referenced model as mixed content if the
|
|
906
|
-
`mixed: true` is added when referencing it.
|
|
907
|
-
|
|
908
|
-
Syntax:
|
|
909
|
-
|
|
910
|
-
[source,ruby]
|
|
911
|
-
----
|
|
912
|
-
xml do
|
|
913
|
-
map_element 'xml_element_name', to: :name_of_attribute, mixed: true
|
|
914
|
-
end
|
|
915
|
-
----
|
|
916
|
-
|
|
917
|
-
.Applying `mixed` to treat an inner element as mixed content
|
|
918
|
-
[example]
|
|
919
|
-
====
|
|
920
|
-
[source,ruby]
|
|
921
|
-
----
|
|
922
|
-
class Paragraph < Lutaml::Model::Serializable
|
|
923
|
-
attribute :bold, :string
|
|
924
|
-
attribute :italic, :string
|
|
925
|
-
|
|
926
|
-
xml do
|
|
927
|
-
root 'p'
|
|
928
|
-
|
|
929
|
-
map_element 'bold', to: :bold
|
|
930
|
-
map_element 'i', to: :italic
|
|
931
|
-
end
|
|
932
|
-
end
|
|
933
|
-
|
|
934
|
-
class Description < Lutaml::Model::Serializable
|
|
935
|
-
attribute :paragraph, Paragraph
|
|
936
|
-
|
|
937
|
-
xml do
|
|
938
|
-
root 'description'
|
|
939
|
-
|
|
940
|
-
map_element 'p', to: :paragraph, mixed: true
|
|
941
|
-
end
|
|
942
|
-
end
|
|
943
|
-
----
|
|
944
|
-
|
|
945
|
-
[source,ruby]
|
|
946
|
-
----
|
|
947
|
-
> Description.from_xml("<description><p>My name is <bold>John Doe</bold>, and I'm <i>28</i> years old</p></description>")
|
|
948
|
-
> #<Description:0x0000000104ac7240 @paragraph=#<Paragraph:0x0000000104ac7240 @bold="John Doe", @italic="28">>
|
|
949
|
-
> Description.new(paragraph: Paragraph.new(bold: "John Doe", italic: "28")).to_xml
|
|
950
|
-
> #<description><p>My name is <bold>John Doe</bold>, and I'm <i>28</i> years old</p></description>
|
|
951
|
-
----
|
|
952
|
-
====
|
|
953
|
-
|
|
954
950
|
|
|
955
951
|
=== Key value data models
|
|
956
952
|
|
|
@@ -1579,7 +1575,7 @@ Lutaml::Model::Config.configure do |config|
|
|
|
1579
1575
|
end
|
|
1580
1576
|
----
|
|
1581
1577
|
|
|
1582
|
-
You can also provide the adapter type by using symbols like
|
|
1578
|
+
You can also provide the adapter type by using symbols like
|
|
1583
1579
|
|
|
1584
1580
|
[source,ruby]
|
|
1585
1581
|
----
|
|
@@ -1765,6 +1761,11 @@ differences in implementation.
|
|
|
1765
1761
|
|
|
1766
1762
|
4+h| XML features
|
|
1767
1763
|
|
|
1764
|
+
| <<root-namespace,XML default namespace>>
|
|
1765
|
+
| Yes. Supports `<root xmlns='http://example.com'>` through the `namespace` option without prefix.
|
|
1766
|
+
| No. Only supports `<root xmlns:prefix='http://example.com'>`.
|
|
1767
|
+
|
|
|
1768
|
+
|
|
1768
1769
|
| XML mixed content support
|
|
1769
1770
|
| Yes. Supports the following kind of XML through <<mixed-content,mixed content>> support.
|
|
1770
1771
|
|
|
@@ -276,7 +276,10 @@ module Lutaml
|
|
|
276
276
|
end
|
|
277
277
|
|
|
278
278
|
if rule.custom_methods[:from]
|
|
279
|
-
|
|
279
|
+
if value && !value.empty?
|
|
280
|
+
value = new.send(rule.custom_methods[:from], instance,
|
|
281
|
+
value)
|
|
282
|
+
end
|
|
280
283
|
next
|
|
281
284
|
end
|
|
282
285
|
|
data/lib/lutaml/model/version.rb
CHANGED
|
@@ -17,9 +17,14 @@ module Lutaml
|
|
|
17
17
|
|
|
18
18
|
def initialize(xml)
|
|
19
19
|
@xml = xml
|
|
20
|
+
@current_namespace = nil
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
def create_element(name, attributes = {})
|
|
24
|
+
if @current_namespace && !name.start_with?("#{@current_namespace}:")
|
|
25
|
+
name = "#{@current_namespace}:#{name}"
|
|
26
|
+
end
|
|
27
|
+
|
|
23
28
|
if block_given?
|
|
24
29
|
xml.element(name, attributes) do |element|
|
|
25
30
|
yield(self.class.new(element))
|
|
@@ -36,6 +41,8 @@ module Lutaml
|
|
|
36
41
|
def create_and_add_element(element_name, prefix: nil, attributes: {})
|
|
37
42
|
prefixed_name = if prefix
|
|
38
43
|
"#{prefix}:#{element_name}"
|
|
44
|
+
elsif @current_namespace && !element_name.start_with?("#{@current_namespace}:")
|
|
45
|
+
"#{@current_namespace}:#{element_name}"
|
|
39
46
|
else
|
|
40
47
|
element_name
|
|
41
48
|
end
|
|
@@ -47,6 +54,8 @@ module Lutaml
|
|
|
47
54
|
else
|
|
48
55
|
xml.element(prefixed_name, attributes)
|
|
49
56
|
end
|
|
57
|
+
|
|
58
|
+
@current_namespace = nil
|
|
50
59
|
end
|
|
51
60
|
|
|
52
61
|
def <<(text)
|
|
@@ -59,9 +68,10 @@ module Lutaml
|
|
|
59
68
|
|
|
60
69
|
# Add XML namespace to document
|
|
61
70
|
#
|
|
62
|
-
# Ox doesn't support XML namespaces so
|
|
63
|
-
|
|
64
|
-
|
|
71
|
+
# Ox doesn't support XML namespaces so we only save the
|
|
72
|
+
# current namespace prefix to add it to the element's name later.
|
|
73
|
+
def add_namespace_prefix(prefix)
|
|
74
|
+
@current_namespace = prefix
|
|
65
75
|
self
|
|
66
76
|
end
|
|
67
77
|
|
|
@@ -20,6 +20,8 @@ module Lutaml
|
|
|
20
20
|
elsif ordered?(@root, options)
|
|
21
21
|
build_ordered_element(builder, @root, options)
|
|
22
22
|
else
|
|
23
|
+
mapper_class = options[:mapper_class] || @root.class
|
|
24
|
+
options[:xml_attributes] = build_namespace_attributes(mapper_class)
|
|
23
25
|
build_element(builder, @root, options)
|
|
24
26
|
end
|
|
25
27
|
|
|
@@ -46,6 +48,7 @@ module Lutaml
|
|
|
46
48
|
curr_index = index_hash[name] += 1
|
|
47
49
|
|
|
48
50
|
element_rule = xml_mapping.find_by_name(name)
|
|
51
|
+
next if element_rule.nil?
|
|
49
52
|
|
|
50
53
|
attribute_def = attribute_definition_for(element, element_rule,
|
|
51
54
|
mapper_class: mapper_class)
|
|
@@ -160,10 +160,10 @@ module Lutaml
|
|
|
160
160
|
prefixed_xml = xml.add_namespace_prefix(prefix)
|
|
161
161
|
tag_name = options[:tag_name] || xml_mapping.root_element
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
163
|
+
prefixed_xml.create_and_add_element(tag_name, prefix: prefix,
|
|
164
|
+
attributes: attributes) do
|
|
165
165
|
if options.key?(:namespace_prefix) && !options[:namespace_prefix]
|
|
166
|
-
|
|
166
|
+
prefixed_xml.add_namespace_prefix(nil)
|
|
167
167
|
end
|
|
168
168
|
|
|
169
169
|
xml_mapping.elements.each do |element_rule|
|
|
@@ -177,7 +177,7 @@ module Lutaml
|
|
|
177
177
|
value = [value] if attribute_def.collection? && !value.is_a?(Array)
|
|
178
178
|
|
|
179
179
|
add_to_xml(
|
|
180
|
-
|
|
180
|
+
prefixed_xml,
|
|
181
181
|
element_rule.prefix,
|
|
182
182
|
value,
|
|
183
183
|
options.merge({ attribute: attribute_def, rule: element_rule }),
|
|
@@ -212,9 +212,11 @@ module Lutaml
|
|
|
212
212
|
|
|
213
213
|
attrs = {}
|
|
214
214
|
|
|
215
|
-
if xml_mappings.
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
if xml_mappings.namespace_uri
|
|
216
|
+
prefixed_name = ["xmlns",
|
|
217
|
+
xml_mappings.namespace_prefix].compact.join(":")
|
|
218
|
+
|
|
219
|
+
attrs[prefixed_name] = xml_mappings.namespace_uri
|
|
218
220
|
end
|
|
219
221
|
|
|
220
222
|
xml_mappings.mappings.each do |mapping_rule|
|
|
@@ -44,8 +44,7 @@ module Lutaml
|
|
|
44
44
|
delegate: nil,
|
|
45
45
|
namespace: (namespace_set = false
|
|
46
46
|
nil),
|
|
47
|
-
prefix: nil
|
|
48
|
-
mixed: false
|
|
47
|
+
prefix: nil
|
|
49
48
|
)
|
|
50
49
|
@elements[name] = XmlMappingRule.new(
|
|
51
50
|
name,
|
|
@@ -55,7 +54,6 @@ module Lutaml
|
|
|
55
54
|
delegate: delegate,
|
|
56
55
|
namespace: namespace,
|
|
57
56
|
prefix: prefix,
|
|
58
|
-
mixed_content: mixed,
|
|
59
57
|
namespace_set: namespace_set != false,
|
|
60
58
|
)
|
|
61
59
|
end
|
data/lutaml-model.gemspec
CHANGED
metadata
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: lutaml-model
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2024-
|
|
11
|
+
date: 2024-09-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bigdecimal
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
13
27
|
- !ruby/object:Gem::Dependency
|
|
14
28
|
name: thor
|
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|