lutaml-model 0.3.20 → 0.3.22
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 +5 -5
- data/README.adoc +19 -16
- data/lib/lutaml/model/attribute.rb +4 -2
- data/lib/lutaml/model/serialize.rb +9 -6
- 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 +7 -3
- data/lib/lutaml/model/xml_adapter/ox_adapter.rb +2 -0
- data/lib/lutaml/model/xml_adapter/xml_document.rb +18 -8
- data/lib/lutaml/model/xml_mapping.rb +6 -3
- 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: 3d740eaaa52ff7479fc3e0f23aa3fb308bd8b61f820ac22f036b31f24d696989
|
4
|
+
data.tar.gz: '0294c66616f39e84e931b626f776ee555450ac962018bf3189200467761e2707'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56675b27dfbf1fa77986f5793f48dd8f5b53b69d5fa989209f79c1f2827ee0ed46eeeeecaed72904be2053a12c4653dab5d06dd0b1401754a06e9a0a9db8fc0f
|
7
|
+
data.tar.gz: cedbee96c00a6d43065df43acc8ee7d5262bd03265fda81fc85698c1abb7c00f0989c7cc9d1afe1f5038b4323e886adadd0609250dd9f952e2e1b33fcc9b7fee
|
data/.rubocop_todo.yml
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2024-
|
3
|
+
# on 2024-11-03 22:29:56 UTC using RuboCop version 1.66.1.
|
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
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count:
|
9
|
+
# Offense count: 124
|
10
10
|
# This cop supports safe autocorrection (--autocorrect).
|
11
11
|
# Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
|
12
12
|
# URISchemes: http, https
|
@@ -46,7 +46,7 @@ Metrics/AbcSize:
|
|
46
46
|
- 'lib/lutaml/model/xml_adapter/xml_document.rb'
|
47
47
|
- 'lib/lutaml/model/xml_mapping_rule.rb'
|
48
48
|
|
49
|
-
# Offense count:
|
49
|
+
# Offense count: 6
|
50
50
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
|
51
51
|
# AllowedMethods: refine
|
52
52
|
Metrics/BlockLength:
|
@@ -67,7 +67,7 @@ Metrics/CyclomaticComplexity:
|
|
67
67
|
# Offense count: 51
|
68
68
|
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
|
69
69
|
Metrics/MethodLength:
|
70
|
-
Max:
|
70
|
+
Max: 46
|
71
71
|
|
72
72
|
# Offense count: 7
|
73
73
|
# Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
|
@@ -95,7 +95,7 @@ RSpec/ContextWording:
|
|
95
95
|
- 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
|
96
96
|
- 'spec/lutaml/model/xml_mapping_spec.rb'
|
97
97
|
|
98
|
-
# Offense count:
|
98
|
+
# Offense count: 110
|
99
99
|
# Configuration parameters: CountAsOne.
|
100
100
|
RSpec/ExampleLength:
|
101
101
|
Max: 54
|
data/README.adoc
CHANGED
@@ -157,22 +157,27 @@ Syntax:
|
|
157
157
|
attribute :name_of_attribute, {symbol | string | class}
|
158
158
|
----
|
159
159
|
|
160
|
+
.Mapping between Lutaml::Model::Type classes, Ruby equivalents and serialization format types
|
160
161
|
|===
|
161
|
-
|
|
162
|
-
|
163
|
-
| `String` |
|
164
|
-
| `Integer`
|
165
|
-
| `Float` |
|
166
|
-
| `
|
167
|
-
| `
|
168
|
-
| `
|
169
|
-
| `
|
170
|
-
| `
|
171
|
-
| `
|
172
|
-
| `Hash` |
|
162
|
+
| Lutaml::Model::Type | Ruby Class | XML | JSON | YAML | Example Value
|
163
|
+
|
164
|
+
| `:string` | `String` | `xs:string` | `string` | `string` | `"text"`
|
165
|
+
| `:integer` | `Integer` | `xs:integer` | `number` | `integer` | `42`
|
166
|
+
| `:float` | `Float` | `xs:decimal` | `number` | `float` | `3.14`
|
167
|
+
| `:boolean` | `TrueClass`/`FalseClass` | `xs:boolean` | `boolean` | `boolean` | `true/false`
|
168
|
+
| `:date` | `Date` | `xs:date` | `string` (ISO8601) | `date` | `"2024-01-01"`
|
169
|
+
| `:time_without_date` | `Time` | `xs:time` | `string` (ISO8601) | `time` | `"12:34:56"`
|
170
|
+
| `:date_time` | `DateTime` | `xs:dateTime` | `string` (ISO8601) | `timestamp` | `"2024-01-01T00:00:00Z"`
|
171
|
+
| `:time` | `Time` | `xs:dateTime` | `string` (ISO8601) | `timestamp` | `"2024-01-01T00:00:00Z"`
|
172
|
+
| `:decimal` (optional) | `BigDecimal` | `xs:decimal` | `number` | `float` | `123.45`
|
173
|
+
| `:hash` | `Hash` | complex element | `object` | `map` | `{key: "value"}`
|
174
|
+
| `class` | Custom Class | complex element | `object` | `map` | `CustomObject`
|
175
|
+
| `collection: true` | `Array` of Type | repeated elements | `array` | `sequence` | `[obj1, obj2]`
|
176
|
+
// | `any`
|
173
177
|
|
174
178
|
|===
|
175
179
|
|
180
|
+
|
176
181
|
.Defining attributes with supported types via symbol, string and class
|
177
182
|
[example]
|
178
183
|
====
|
@@ -538,8 +543,7 @@ For the following xml
|
|
538
543
|
@description="\n A <b>fictional person</b> commonly used as a <i>placeholder name</i>.\n ",
|
539
544
|
@element_order=["text", "name", "text", "description", "text"],
|
540
545
|
@name="John Doe",
|
541
|
-
@ordered=nil
|
542
|
-
@validate_on_set=false>
|
546
|
+
@ordered=nil>
|
543
547
|
----
|
544
548
|
====
|
545
549
|
|
@@ -1774,8 +1778,7 @@ end
|
|
1774
1778
|
@name="Masterpiece: Vase",
|
1775
1779
|
@ordered=nil,
|
1776
1780
|
@size=12,
|
1777
|
-
@description="A beautiful ceramic vase"
|
1778
|
-
@validate_on_set=false>
|
1781
|
+
@description="A beautiful ceramic vase">
|
1779
1782
|
> puts CustomCeramic.new(name: "Vase", size: 12, description: "A beautiful vase").to_xml
|
1780
1783
|
# <CustomCeramic Size="15">
|
1781
1784
|
# <Name>XML Masterpiece: Vase</Name>
|
@@ -217,7 +217,8 @@ module Lutaml
|
|
217
217
|
|
218
218
|
def validate_options!(options)
|
219
219
|
if (invalid_opts = options.keys - ALLOWED_OPTIONS).any?
|
220
|
-
raise StandardError,
|
220
|
+
raise StandardError,
|
221
|
+
"Invalid options given for `#{name}` #{invalid_opts}"
|
221
222
|
end
|
222
223
|
end
|
223
224
|
|
@@ -225,7 +226,8 @@ module Lutaml
|
|
225
226
|
return true if type.is_a?(Class)
|
226
227
|
return true if [Symbol, String].include?(type.class) && cast_type!(type)
|
227
228
|
|
228
|
-
raise ArgumentError,
|
229
|
+
raise ArgumentError,
|
230
|
+
"Invalid type: #{type}, must be a Symbol, String or a Class"
|
229
231
|
end
|
230
232
|
end
|
231
233
|
end
|
@@ -32,7 +32,8 @@ module Lutaml
|
|
32
32
|
@mappings ||= {}
|
33
33
|
@attributes ||= {}
|
34
34
|
|
35
|
-
subclass.instance_variable_set(:@attributes,
|
35
|
+
subclass.instance_variable_set(:@attributes,
|
36
|
+
Utils.deep_dup(@attributes))
|
36
37
|
subclass.instance_variable_set(:@mappings, Utils.deep_dup(@mappings))
|
37
38
|
subclass.instance_variable_set(:@model, subclass)
|
38
39
|
end
|
@@ -51,17 +52,20 @@ module Lutaml
|
|
51
52
|
Utils.add_boolean_accessor_if_not_defined(klass, :mixed)
|
52
53
|
Utils.add_accessor_if_not_defined(klass, :element_order)
|
53
54
|
|
54
|
-
Utils.add_method_if_not_defined(klass,
|
55
|
+
Utils.add_method_if_not_defined(klass,
|
56
|
+
:using_default_for) do |attribute_name|
|
55
57
|
@using_default ||= {}
|
56
58
|
@using_default[attribute_name] = true
|
57
59
|
end
|
58
60
|
|
59
|
-
Utils.add_method_if_not_defined(klass,
|
61
|
+
Utils.add_method_if_not_defined(klass,
|
62
|
+
:value_set_for) do |attribute_name|
|
60
63
|
@using_default ||= {}
|
61
64
|
@using_default[attribute_name] = false
|
62
65
|
end
|
63
66
|
|
64
|
-
Utils.add_method_if_not_defined(klass,
|
67
|
+
Utils.add_method_if_not_defined(klass,
|
68
|
+
:using_default?) do |attribute_name|
|
65
69
|
@using_default ||= {}
|
66
70
|
!!@using_default[attribute_name]
|
67
71
|
end
|
@@ -446,8 +450,7 @@ module Lutaml
|
|
446
450
|
attr_writer :ordered, :mixed
|
447
451
|
|
448
452
|
def initialize(attrs = {})
|
449
|
-
@
|
450
|
-
@using_default ||= {}
|
453
|
+
@using_default = {}
|
451
454
|
|
452
455
|
return unless self.class.attributes
|
453
456
|
|
data/lib/lutaml/model/version.rb
CHANGED
@@ -128,12 +128,15 @@ module Lutaml
|
|
128
128
|
)
|
129
129
|
end
|
130
130
|
|
131
|
-
|
131
|
+
if root_node.nil? && !node.namespace&.prefix
|
132
|
+
default_namespace = node.namespace&.href
|
133
|
+
end
|
132
134
|
|
133
135
|
super(
|
134
136
|
node,
|
135
137
|
attributes,
|
136
|
-
parse_all_children(node, root_node: root_node || self,
|
138
|
+
parse_all_children(node, root_node: root_node || self,
|
139
|
+
default_namespace: default_namespace),
|
137
140
|
node.text,
|
138
141
|
parent_document: root_node,
|
139
142
|
namespace_prefix: node.namespace&.prefix,
|
@@ -182,7 +185,8 @@ module Lutaml
|
|
182
185
|
|
183
186
|
def parse_all_children(node, root_node: nil, default_namespace: nil)
|
184
187
|
node.children.map do |child|
|
185
|
-
NokogiriElement.new(child, root_node: root_node,
|
188
|
+
NokogiriElement.new(child, root_node: root_node,
|
189
|
+
default_namespace: default_namespace)
|
186
190
|
end
|
187
191
|
end
|
188
192
|
|
@@ -89,6 +89,8 @@ module Lutaml
|
|
89
89
|
def initialize(node, root_node: nil)
|
90
90
|
if node.is_a?(String)
|
91
91
|
super("text", {}, [], node, parent_document: root_node)
|
92
|
+
elsif node.is_a?(Ox::Comment)
|
93
|
+
super("comment", {}, [], node.value, parent_document: root_node)
|
92
94
|
else
|
93
95
|
namespace_attributes(node.attributes).each do |(name, value)|
|
94
96
|
if root_node
|
@@ -77,7 +77,10 @@ module Lutaml
|
|
77
77
|
result.item_order = element.order
|
78
78
|
|
79
79
|
element.children.each_with_object(result) do |child, hash|
|
80
|
-
|
80
|
+
if klass&.<= Serialize
|
81
|
+
attr = klass.attribute_for_child(child.name,
|
82
|
+
format)
|
83
|
+
end
|
81
84
|
|
82
85
|
value = if child.text?
|
83
86
|
child.text
|
@@ -136,7 +139,8 @@ module Lutaml
|
|
136
139
|
rule = options[:rule]
|
137
140
|
|
138
141
|
if rule.custom_methods[:to]
|
139
|
-
options[:mapper_class].new.send(rule.custom_methods[:to], element,
|
142
|
+
options[:mapper_class].new.send(rule.custom_methods[:to], element,
|
143
|
+
xml.parent, xml)
|
140
144
|
return
|
141
145
|
end
|
142
146
|
|
@@ -203,7 +207,8 @@ module Lutaml
|
|
203
207
|
end
|
204
208
|
|
205
209
|
xml_mapping.attributes.each do |attribute_rule|
|
206
|
-
attribute_rule.serialize_attribute(element, prefixed_xml.parent,
|
210
|
+
attribute_rule.serialize_attribute(element, prefixed_xml.parent,
|
211
|
+
xml)
|
207
212
|
end
|
208
213
|
|
209
214
|
xml_mapping.elements.each do |element_rule|
|
@@ -223,11 +228,13 @@ module Lutaml
|
|
223
228
|
element,
|
224
229
|
element_rule.prefix,
|
225
230
|
value,
|
226
|
-
options.merge({ attribute: attribute_def, rule: element_rule,
|
231
|
+
options.merge({ attribute: attribute_def, rule: element_rule,
|
232
|
+
mapper_class: mapper_class }),
|
227
233
|
)
|
228
234
|
end
|
229
235
|
|
230
|
-
process_content_mapping(element, xml_mapping.content_mapping,
|
236
|
+
process_content_mapping(element, xml_mapping.content_mapping,
|
237
|
+
prefixed_xml)
|
231
238
|
|
232
239
|
process_raw_mapping(element, xml_mapping.raw_mapping, prefixed_xml)
|
233
240
|
end
|
@@ -318,7 +325,8 @@ module Lutaml
|
|
318
325
|
next unless type
|
319
326
|
|
320
327
|
if type <= Lutaml::Model::Serialize
|
321
|
-
attrs = attrs.merge(build_namespace_attributes(type, processed,
|
328
|
+
attrs = attrs.merge(build_namespace_attributes(type, processed,
|
329
|
+
{ caller_rule: mapping_rule }))
|
322
330
|
end
|
323
331
|
|
324
332
|
if mapping_rule.namespace && mapping_rule.prefix && mapping_rule.name != "lang"
|
@@ -348,8 +356,10 @@ module Lutaml
|
|
348
356
|
hash["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
|
349
357
|
end
|
350
358
|
|
351
|
-
if render_element?(mapping_rule, element,
|
352
|
-
|
359
|
+
if render_element?(mapping_rule, element,
|
360
|
+
mapping_rule.to_value_for(element))
|
361
|
+
hash[mapping_rule.prefixed_name] =
|
362
|
+
mapping_rule.to_value_for(element)
|
353
363
|
end
|
354
364
|
end
|
355
365
|
|
@@ -222,12 +222,15 @@ module Lutaml
|
|
222
222
|
|
223
223
|
def deep_dup
|
224
224
|
self.class.new.tap do |xml_mapping|
|
225
|
-
xml_mapping.root(@root_element.dup, mixed: @mixed_content,
|
225
|
+
xml_mapping.root(@root_element.dup, mixed: @mixed_content,
|
226
|
+
ordered: @ordered)
|
226
227
|
xml_mapping.namespace(@namespace_uri.dup, @namespace_prefix.dup)
|
227
228
|
|
228
|
-
xml_mapping.instance_variable_set(:@attributes,
|
229
|
+
xml_mapping.instance_variable_set(:@attributes,
|
230
|
+
dup_mappings(@attributes))
|
229
231
|
xml_mapping.instance_variable_set(:@elements, dup_mappings(@elements))
|
230
|
-
xml_mapping.instance_variable_set(:@content_mapping,
|
232
|
+
xml_mapping.instance_variable_set(:@content_mapping,
|
233
|
+
@content_mapping&.deep_dup)
|
231
234
|
end
|
232
235
|
end
|
233
236
|
|
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.22
|
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-
|
11
|
+
date: 2024-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|