lutaml-model 0.3.17 → 0.3.19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lutaml/model/mapping_hash.rb +1 -1
- data/lib/lutaml/model/serialize.rb +1 -1
- data/lib/lutaml/model/version.rb +1 -1
- data/lib/lutaml/model/xml_adapter/builder/nokogiri.rb +1 -1
- data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +16 -9
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +12 -4
- data/lib/lutaml/model/xml_adapter/xml_document.rb +2 -5
- data/lib/lutaml/model/xml_adapter/xml_element.rb +30 -7
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa234d9dee0cbe45d559e6f4141d81ac6eecbb8c931afa77ec82f5d6d9129267
|
4
|
+
data.tar.gz: cee349d535ecbc950629123438ca1d3d2161288984806d49857d2dd215e4d1ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5825d1afeb2bef26607379380722a9506795cce5635132355785ddece46086f1a16644b7d7c8960c9f103816e80bdd97d8d01e7f2d1790c3328dfbe1afdab5c
|
7
|
+
data.tar.gz: 14bd971607b8420c45bf3cda5badc91ddfeeb82e83918e5eb85f529fe807b7c1c25e02480412db33b91d80cebc4c6f1929e14ca946d9ef2c9ec1ed621239d508
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -15,7 +15,7 @@ module Lutaml
|
|
15
15
|
def to_xml(options = {})
|
16
16
|
builder = Builder::Nokogiri.build(encoding: "UTF-8") do |xml|
|
17
17
|
if root.is_a?(Lutaml::Model::XmlAdapter::NokogiriElement)
|
18
|
-
root.
|
18
|
+
root.build_xml(xml)
|
19
19
|
else
|
20
20
|
mapper_class = options[:mapper_class] || @root.class
|
21
21
|
options[:xml_attributes] =
|
@@ -73,11 +73,9 @@ module Lutaml
|
|
73
73
|
text = xml_mapping.content_mapping.serialize(element)
|
74
74
|
text = text[curr_index] if text.is_a?(Array)
|
75
75
|
|
76
|
-
if element.mixed?
|
77
|
-
|
78
|
-
|
79
|
-
content << text
|
80
|
-
end
|
76
|
+
next prefixed_xml.text(text) if element.mixed?
|
77
|
+
|
78
|
+
content << text
|
81
79
|
elsif !value.nil? || element_rule.render_nil?
|
82
80
|
value = value[curr_index] if attribute_def.collection?
|
83
81
|
|
@@ -89,6 +87,7 @@ module Lutaml
|
|
89
87
|
options.merge(
|
90
88
|
attribute: attribute_def,
|
91
89
|
rule: element_rule,
|
90
|
+
mapper_class: mapper_class,
|
92
91
|
),
|
93
92
|
)
|
94
93
|
end
|
@@ -124,9 +123,11 @@ module Lutaml
|
|
124
123
|
namespace_prefix: attr.namespace&.prefix,
|
125
124
|
)
|
126
125
|
end
|
126
|
+
|
127
127
|
default_namespace = node.namespace&.href if root_node.nil?
|
128
|
+
|
128
129
|
super(
|
129
|
-
node
|
130
|
+
node,
|
130
131
|
attributes,
|
131
132
|
parse_all_children(node, root_node: root_node || self, default_namespace: default_namespace),
|
132
133
|
node.text,
|
@@ -141,7 +142,13 @@ module Lutaml
|
|
141
142
|
children.empty? && text.length.positive?
|
142
143
|
end
|
143
144
|
|
144
|
-
def to_xml
|
145
|
+
def to_xml
|
146
|
+
return text if text?
|
147
|
+
|
148
|
+
build_xml.doc.root.to_xml
|
149
|
+
end
|
150
|
+
|
151
|
+
def build_xml(builder = nil)
|
145
152
|
builder ||= Builder::Nokogiri.build
|
146
153
|
|
147
154
|
if name == "text"
|
@@ -149,7 +156,7 @@ module Lutaml
|
|
149
156
|
else
|
150
157
|
builder.public_send(name, build_attributes(self)) do |xml|
|
151
158
|
children.each do |child|
|
152
|
-
child.
|
159
|
+
child.build_xml(xml)
|
153
160
|
end
|
154
161
|
end
|
155
162
|
end
|
@@ -16,7 +16,7 @@ module Lutaml
|
|
16
16
|
builder = Builder::Ox.build
|
17
17
|
|
18
18
|
if @root.is_a?(Lutaml::Model::XmlAdapter::OxElement)
|
19
|
-
@root.
|
19
|
+
@root.build_xml(builder)
|
20
20
|
elsif ordered?(@root, options)
|
21
21
|
build_ordered_element(builder, @root, options)
|
22
22
|
else
|
@@ -117,7 +117,7 @@ module Lutaml
|
|
117
117
|
end
|
118
118
|
|
119
119
|
super(
|
120
|
-
node
|
120
|
+
node,
|
121
121
|
attributes,
|
122
122
|
parse_children(node, root_node: root_node || self),
|
123
123
|
node.text,
|
@@ -126,7 +126,13 @@ module Lutaml
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
def to_xml
|
129
|
+
def to_xml
|
130
|
+
return text if text?
|
131
|
+
|
132
|
+
build_xml.xml.to_s
|
133
|
+
end
|
134
|
+
|
135
|
+
def build_xml(builder = nil)
|
130
136
|
builder ||= Builder::Ox.build
|
131
137
|
attrs = build_attributes(self)
|
132
138
|
|
@@ -134,9 +140,11 @@ module Lutaml
|
|
134
140
|
builder.add_text(builder, text)
|
135
141
|
else
|
136
142
|
builder.create_and_add_element(name, attributes: attrs) do |el|
|
137
|
-
children.each { |child| child.
|
143
|
+
children.each { |child| child.build_xml(el) }
|
138
144
|
end
|
139
145
|
end
|
146
|
+
|
147
|
+
builder
|
140
148
|
end
|
141
149
|
|
142
150
|
def namespace_attributes(attributes)
|
@@ -73,6 +73,7 @@ module Lutaml
|
|
73
73
|
|
74
74
|
def parse_element(element, klass = nil, format = nil)
|
75
75
|
result = Lutaml::Model::MappingHash.new
|
76
|
+
result.node = element
|
76
77
|
result.item_order = element.order
|
77
78
|
|
78
79
|
element.children.each_with_object(result) do |child, hash|
|
@@ -81,11 +82,7 @@ module Lutaml
|
|
81
82
|
value = if child.text?
|
82
83
|
child.text
|
83
84
|
elsif attr&.raw?
|
84
|
-
child.children.map
|
85
|
-
next c.text if c.text?
|
86
|
-
|
87
|
-
c.to_xml.doc.root.to_xml({})
|
88
|
-
end.join
|
85
|
+
child.children.map(&:to_xml).join
|
89
86
|
else
|
90
87
|
parse_element(child, attr&.type || klass, format)
|
91
88
|
end
|
@@ -10,8 +10,10 @@ module Lutaml
|
|
10
10
|
:namespace_prefix,
|
11
11
|
:parent_document
|
12
12
|
|
13
|
+
attr_accessor :adapter_node
|
14
|
+
|
13
15
|
def initialize(
|
14
|
-
|
16
|
+
node,
|
15
17
|
attributes = {},
|
16
18
|
children = [],
|
17
19
|
text = nil,
|
@@ -19,13 +21,22 @@ module Lutaml
|
|
19
21
|
namespace_prefix: nil,
|
20
22
|
default_namespace: nil
|
21
23
|
)
|
22
|
-
@name = extract_name(
|
23
|
-
@namespace_prefix = namespace_prefix || extract_namespace_prefix(
|
24
|
-
@attributes = attributes
|
24
|
+
@name = extract_name(node)
|
25
|
+
@namespace_prefix = namespace_prefix || extract_namespace_prefix(node)
|
26
|
+
@attributes = attributes
|
25
27
|
@children = children
|
26
28
|
@text = text
|
27
29
|
@parent_document = parent_document
|
28
30
|
@default_namespace = default_namespace
|
31
|
+
|
32
|
+
self.adapter_node = node
|
33
|
+
end
|
34
|
+
|
35
|
+
# This tells which attributes to pretty print, So we remove the
|
36
|
+
# @parent_document and @adapter_node because they were causing
|
37
|
+
# so much repeatative output.
|
38
|
+
def pretty_print_instance_variables
|
39
|
+
(instance_variables - %i[@adapter_node @parent_document]).sort
|
29
40
|
end
|
30
41
|
|
31
42
|
def name
|
@@ -79,20 +90,32 @@ module Lutaml
|
|
79
90
|
namespaces[nil] || @parent_document&.namespaces&.dig(nil)
|
80
91
|
end
|
81
92
|
|
82
|
-
def extract_name(
|
83
|
-
|
93
|
+
def extract_name(node)
|
94
|
+
name = name_from_node(node)
|
95
|
+
|
96
|
+
n = name.split(":")
|
84
97
|
return name if n.length <= 1
|
85
98
|
|
86
99
|
n[1..].join(":")
|
87
100
|
end
|
88
101
|
|
89
|
-
def extract_namespace_prefix(
|
102
|
+
def extract_namespace_prefix(node)
|
103
|
+
name = name_from_node(node)
|
104
|
+
|
90
105
|
n = name.to_s.split(":")
|
91
106
|
return if n.length <= 1
|
92
107
|
|
93
108
|
n.first
|
94
109
|
end
|
95
110
|
|
111
|
+
def name_from_node(node)
|
112
|
+
if node.is_a?(String)
|
113
|
+
node
|
114
|
+
else
|
115
|
+
node.name.to_s
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
96
119
|
def order
|
97
120
|
children.each_with_object([]) do |child, arr|
|
98
121
|
arr << child.unprefixed_name
|
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.3.
|
4
|
+
version: 0.3.19
|
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-10-
|
11
|
+
date: 2024-10-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|