lutaml-model 0.3.11 → 0.3.13

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.

Potentially problematic release.


This version of lutaml-model might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91ff48fd66cf1435e5e18508b24cc24f7cc92dc8b5d1619c7796932eb21dcea2
4
- data.tar.gz: 51eabdb2aede716ce86cea46325cad0b7b9f0da98df3235fc3b8596fe9f96bd9
3
+ metadata.gz: c7a3ca13f464d886f1f30bb695cc5b98151c86771214665e77734b308e4ae6e0
4
+ data.tar.gz: '08cf720cab0dadca493262a8fec1dbd14ffb6db53ea9f047fe978249f4c299a5'
5
5
  SHA512:
6
- metadata.gz: 3ce25727c43d1c25f97e49c529c9ded5f51d8f2c13ae2766dba8c94d2c1d9a7c646bad564bfb9cd4c5555ee71395f6ff39023268e9e92044f10985c20dd826ca
7
- data.tar.gz: edf1d699e944a2427b947e1a262258e93623c44bc765a5f5497c13bd4d806984722ececd6318254c15196d435b2b809f44389a1be1d9cd5f33e005169b232eaf
6
+ metadata.gz: bbc204ba771660eecbc9eca1b14d37470f6175fb8bb00910bc478f0928a7d03fb95f0b364339d129c1b7d9116c46be8c96344e2c944ca0061bc74ee028069c15
7
+ data.tar.gz: b36bd0b23f8b16ac5921ea63d187cb9c95ea1c819fc92f7007133c40580ad3a88dd4e3a50d9fa541dad9f21895fb9f5330ab45c74d8727c9b7604d3941e29b90
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-09-23 15:00:23 UTC using RuboCop version 1.65.1.
3
+ # on 2024-10-08 13:33:09 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: 100
9
+ # Offense count: 108
10
10
  # This cop supports safe autocorrection (--autocorrect).
11
11
  # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
12
12
  # URISchemes: http, https
@@ -30,7 +30,7 @@ Lint/DuplicateMethods:
30
30
  Exclude:
31
31
  - 'lib/lutaml/model/attribute.rb'
32
32
 
33
- # Offense count: 34
33
+ # Offense count: 35
34
34
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
35
35
  Metrics/AbcSize:
36
36
  Exclude:
@@ -49,9 +49,9 @@ Metrics/AbcSize:
49
49
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
50
50
  # AllowedMethods: refine
51
51
  Metrics/BlockLength:
52
- Max: 42
52
+ Max: 47
53
53
 
54
- # Offense count: 26
54
+ # Offense count: 27
55
55
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
56
56
  Metrics/CyclomaticComplexity:
57
57
  Exclude:
@@ -63,7 +63,7 @@ Metrics/CyclomaticComplexity:
63
63
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
64
64
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
65
65
 
66
- # Offense count: 45
66
+ # Offense count: 46
67
67
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
68
68
  Metrics/MethodLength:
69
69
  Max: 51
@@ -71,7 +71,7 @@ Metrics/MethodLength:
71
71
  # Offense count: 4
72
72
  # Configuration parameters: CountKeywordArgs, MaxOptionalParameters.
73
73
  Metrics/ParameterLists:
74
- Max: 10
74
+ Max: 11
75
75
 
76
76
  # Offense count: 22
77
77
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
@@ -123,7 +123,7 @@ RSpec/MultipleDescribes:
123
123
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
124
124
  - 'spec/lutaml/model/xml_adapter_spec.rb'
125
125
 
126
- # Offense count: 98
126
+ # Offense count: 99
127
127
  RSpec/MultipleExpectations:
128
128
  Max: 14
129
129
 
data/README.adoc CHANGED
@@ -423,6 +423,51 @@ end
423
423
  ----
424
424
  ====
425
425
 
426
+ === Attribute as raw string
427
+
428
+ An attribute can be set to read the value as raw string for XML, by using the `raw: true` option.
429
+
430
+ Syntax:
431
+
432
+ [source,ruby]
433
+ ----
434
+ attribute :name_of_attribute, :string, raw: true
435
+ ----
436
+
437
+ .Using the `raw` option to read raw value for an XML attribute
438
+ [example]
439
+ ====
440
+ [source,ruby]
441
+ ----
442
+ class Person < Lutaml::Model::Serializable
443
+ attribute :name, :string
444
+ attribute :description, :string, raw: true
445
+ end
446
+ ----
447
+
448
+ For the following xml
449
+ [source,xml]
450
+ ----
451
+ <Person>
452
+ <name>John Doe</name>
453
+ <description>
454
+ A <b>fictional person</b> commonly used as a <i>placeholder name</i>.
455
+ </description>
456
+ </Person>
457
+ ----
458
+
459
+ [source,ruby]
460
+ ----
461
+ > Person.from_xml(xml)
462
+ > # <Person:0x0000000107a3ca70
463
+ @description="\n A <b>fictional person</b> commonly used as a <i>placeholder name</i>.\n ",
464
+ @element_order=["text", "name", "text", "description", "text"],
465
+ @name="John Doe",
466
+ @ordered=nil,
467
+ @validate_on_set=false>
468
+ ----
469
+ ====
470
+
426
471
  == Serialization model mappings
427
472
 
428
473
  === General
@@ -7,6 +7,7 @@ module Lutaml
7
7
  @name = name
8
8
  @type = cast_type(type)
9
9
  @options = options
10
+ @raw = !!options[:raw]
10
11
 
11
12
  if collection?
12
13
  validate_collection_range
@@ -14,6 +15,10 @@ module Lutaml
14
15
  end
15
16
  end
16
17
 
18
+ def delegate
19
+ @options[:delegate]
20
+ end
21
+
17
22
  def cast_type(type)
18
23
  case type
19
24
  when Class
@@ -45,8 +50,14 @@ module Lutaml
45
50
  !collection?
46
51
  end
47
52
 
53
+ def raw?
54
+ @raw
55
+ end
56
+
48
57
  def default
49
- value = if options[:default].is_a?(Proc)
58
+ value = if delegate
59
+ type.attributes[to].default
60
+ elsif options[:default].is_a?(Proc)
50
61
  options[:default].call
51
62
  else
52
63
  options[:default]
@@ -7,7 +7,8 @@ module Lutaml
7
7
  :custom_methods,
8
8
  :delegate,
9
9
  :mixed_content,
10
- :child_mappings
10
+ :child_mappings,
11
+ :default_namespace
11
12
 
12
13
  def initialize(
13
14
  name,
@@ -18,6 +19,7 @@ module Lutaml
18
19
  mixed_content: false,
19
20
  namespace_set: false,
20
21
  prefix_set: false,
22
+ default_namespace: nil,
21
23
  child_mappings: nil
22
24
  )
23
25
  @name = name
@@ -29,6 +31,7 @@ module Lutaml
29
31
  @namespace_set = namespace_set
30
32
  @prefix_set = prefix_set
31
33
  @child_mappings = child_mappings
34
+ @default_namespace = default_namespace
32
35
  end
33
36
 
34
37
  alias from name
@@ -42,19 +45,35 @@ module Lutaml
42
45
  end
43
46
  end
44
47
 
48
+ def namespaced_name
49
+ if name == "lang"
50
+ "#{prefix}:#{name}"
51
+ elsif namespace || default_namespace
52
+ "#{namespace || default_namespace}:#{name}"
53
+ else
54
+ name
55
+ end
56
+ end
57
+
45
58
  def serialize_attribute(model, element, doc)
46
59
  if custom_methods[:to]
47
60
  model.send(custom_methods[:to], model, element, doc)
48
61
  end
49
62
  end
50
63
 
64
+ def to_value_for(model)
65
+ if delegate
66
+ model.public_send(delegate).public_send(to)
67
+ else
68
+ model.public_send(to)
69
+ end
70
+ end
71
+
51
72
  def serialize(model, parent = nil, doc = nil)
52
73
  if custom_methods[:to]
53
74
  model.send(custom_methods[:to], model, parent, doc)
54
- elsif delegate
55
- model.public_send(delegate).public_send(to)
56
75
  else
57
- model.public_send(to)
76
+ to_value_for(model)
58
77
  end
59
78
  end
60
79
 
@@ -55,6 +55,14 @@ module Lutaml
55
55
  !!@ordered
56
56
  end
57
57
 
58
+ Utils.add_method_if_not_defined(klass, :mixed=) do |mixed|
59
+ @mixed = mixed
60
+ end
61
+
62
+ Utils.add_method_if_not_defined(klass, :mixed?) do
63
+ !!@mixed
64
+ end
65
+
58
66
  Utils.add_method_if_not_defined(klass, :element_order=) do |order|
59
67
  @element_order = order
60
68
  end
@@ -85,7 +93,7 @@ module Lutaml
85
93
  Lutaml::Model::Config::AVAILABLE_FORMATS.each do |format|
86
94
  define_method(format) do |&block|
87
95
  klass = format == :xml ? XmlMapping : KeyValueMapping
88
- mappings[format] = klass.new
96
+ mappings[format] ||= klass.new
89
97
  mappings[format].instance_eval(&block)
90
98
 
91
99
  if format == :xml && !mappings[format].root_element
@@ -107,7 +115,12 @@ module Lutaml
107
115
  end
108
116
  end
109
117
 
110
- apply_mappings(doc.to_h, format)
118
+ if format == :xml
119
+ doc_hash = doc.parse_element(doc.root, self, :xml)
120
+ apply_mappings(doc_hash, format)
121
+ else
122
+ apply_mappings(doc.to_h, format)
123
+ end
111
124
  end
112
125
 
113
126
  define_method(:"to_#{format}") do |instance|
@@ -280,6 +293,12 @@ module Lutaml
280
293
  attributes[rule.delegate].type.attributes[rule.to]
281
294
  end
282
295
 
296
+ def attribute_for_child(child_name, format)
297
+ mapping_rule = mappings_for(format).find_by_name(child_name)
298
+
299
+ attribute_for_rule(mapping_rule) if mapping_rule
300
+ end
301
+
283
302
  def apply_mappings(doc, format, options = {})
284
303
  instance = options[:instance] || model.new
285
304
  return instance if Utils.blank?(doc)
@@ -326,7 +345,8 @@ module Lutaml
326
345
 
327
346
  if instance.respond_to?(:ordered=) && doc.is_a?(Lutaml::Model::MappingHash)
328
347
  instance.element_order = doc.item_order
329
- instance.ordered = mappings_for(:xml).mixed_content? || options[:mixed_content]
348
+ instance.ordered = mappings_for(:xml).ordered? || options[:ordered]
349
+ instance.mixed = mappings_for(:xml).mixed_content? || options[:mixed_content]
330
350
  end
331
351
 
332
352
  if doc["__schema_location"]
@@ -342,8 +362,10 @@ module Lutaml
342
362
 
343
363
  value = if rule.content_mapping?
344
364
  doc["text"]
365
+ elsif doc.key?(rule.namespaced_name.to_s) || doc.key?(rule.namespaced_name.to_sym)
366
+ doc[rule.namespaced_name.to_s] || doc[rule.namespaced_name.to_sym]
345
367
  else
346
- doc[rule.name.to_s] || doc[rule.name.to_sym]
368
+ rule.to_value_for(instance)
347
369
  end
348
370
 
349
371
  value = normalize_xml_value(value, rule)
@@ -407,6 +429,7 @@ module Lutaml
407
429
  end
408
430
 
409
431
  attr_accessor :element_order, :schema_location
432
+ attr_writer :ordered, :mixed
410
433
 
411
434
  def initialize(attrs = {})
412
435
  @validate_on_set = attrs.delete(:validate_on_set) || false
@@ -456,11 +479,11 @@ module Lutaml
456
479
  end
457
480
 
458
481
  def ordered?
459
- @ordered
482
+ !!@ordered
460
483
  end
461
484
 
462
- def ordered=(ordered)
463
- @ordered = ordered
485
+ def mixed?
486
+ !!@mixed
464
487
  end
465
488
 
466
489
  def key_exist?(hash, key)
@@ -116,6 +116,8 @@ module Lutaml
116
116
  def self.normalize_hash(hash)
117
117
  return hash["text"] if hash.keys == ["text"]
118
118
 
119
+ hash = hash.to_h if hash.is_a?(Lutaml::Model::MappingHash)
120
+
119
121
  hash.filter_map do |key, value|
120
122
  next if key == "text"
121
123
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.3.11"
5
+ VERSION = "0.3.13"
6
6
  end
7
7
  end
@@ -63,11 +63,9 @@ module Lutaml
63
63
  self
64
64
  end
65
65
 
66
- def method_missing(method_name, *args)
66
+ def method_missing(method_name, *args, &block)
67
67
  if block_given?
68
- xml.public_send(method_name, *args) do
69
- yield(xml)
70
- end
68
+ xml.public_send(method_name, *args, &block)
71
69
  else
72
70
  xml.public_send(method_name, *args)
73
71
  end
@@ -55,6 +55,7 @@ module Lutaml
55
55
  end
56
56
 
57
57
  index_hash = {}
58
+ content = []
58
59
 
59
60
  element.element_order.each do |name|
60
61
  index_hash[name] ||= -1
@@ -71,7 +72,11 @@ module Lutaml
71
72
  text = xml_mapping.content_mapping.serialize(element)
72
73
  text = text[curr_index] if text.is_a?(Array)
73
74
 
74
- prefixed_xml.text text
75
+ if element.mixed?
76
+ prefixed_xml.text text
77
+ else
78
+ content << text
79
+ end
75
80
  elsif !value.nil? || element_rule.render_nil?
76
81
  value = value[curr_index] if attribute_def.collection?
77
82
 
@@ -87,12 +92,14 @@ module Lutaml
87
92
  )
88
93
  end
89
94
  end
95
+
96
+ prefixed_xml.text content.join
90
97
  end
91
98
  end
92
99
  end
93
100
 
94
101
  class NokogiriElement < XmlElement
95
- def initialize(node, root_node: nil)
102
+ def initialize(node, root_node: nil, default_namespace: nil)
96
103
  if root_node
97
104
  node.namespaces.each do |prefix, name|
98
105
  namespace = XmlNamespace.new(name, prefix)
@@ -116,14 +123,15 @@ module Lutaml
116
123
  namespace_prefix: attr.namespace&.prefix,
117
124
  )
118
125
  end
119
-
126
+ default_namespace = node.namespace&.href if root_node.nil?
120
127
  super(
121
128
  node.name,
122
129
  attributes,
123
- parse_all_children(node, root_node: root_node || self),
130
+ parse_all_children(node, root_node: root_node || self, default_namespace: default_namespace),
124
131
  node.text,
125
132
  parent_document: root_node,
126
133
  namespace_prefix: node.namespace&.prefix,
134
+ default_namespace: default_namespace
127
135
  )
128
136
  end
129
137
 
@@ -138,8 +146,10 @@ module Lutaml
138
146
  if name == "text"
139
147
  builder.text(text)
140
148
  else
141
- builder.send(name, build_attributes(self)) do |xml|
142
- children.each { |child| child.to_xml(xml) }
149
+ builder.public_send(name, build_attributes(self)) do |xml|
150
+ children.each do |child|
151
+ child.to_xml(xml)
152
+ end
143
153
  end
144
154
  end
145
155
 
@@ -154,9 +164,9 @@ module Lutaml
154
164
  end
155
165
  end
156
166
 
157
- def parse_all_children(node, root_node: nil)
167
+ def parse_all_children(node, root_node: nil, default_namespace: nil)
158
168
  node.children.map do |child|
159
- NokogiriElement.new(child, root_node: root_node)
169
+ NokogiriElement.new(child, root_node: root_node, default_namespace: default_namespace)
160
170
  end
161
171
  end
162
172
 
@@ -42,6 +42,7 @@ module Lutaml
42
42
  builder.create_and_add_element(tag_name,
43
43
  attributes: attributes) do |el|
44
44
  index_hash = {}
45
+ content = []
45
46
 
46
47
  element.element_order.each do |name|
47
48
  index_hash[name] ||= -1
@@ -58,7 +59,11 @@ module Lutaml
58
59
  text = element.send(xml_mapping.content_mapping.to)
59
60
  text = text[curr_index] if text.is_a?(Array)
60
61
 
61
- el.add_text(el, text)
62
+ if element.mixed?
63
+ el.add_text(el, text)
64
+ else
65
+ content << text
66
+ end
62
67
  elsif !value.nil? || element_rule.render_nil?
63
68
  value = value[curr_index] if attribute_def.collection?
64
69
 
@@ -74,6 +79,8 @@ module Lutaml
74
79
  )
75
80
  end
76
81
  end
82
+
83
+ el.add_text(el, content.join)
77
84
  end
78
85
  end
79
86
  end
@@ -66,24 +66,43 @@ module Lutaml
66
66
  options[:tag_name] = rule.name
67
67
 
68
68
  options[:mapper_class] = attribute&.type if attribute
69
+ options[:namespace_set] = set_namespace?(rule)
69
70
 
70
71
  options
71
72
  end
72
73
 
73
- def parse_element(element)
74
+ def parse_element(element, klass = nil, format = nil)
74
75
  result = Lutaml::Model::MappingHash.new
75
76
  result.item_order = element.order
76
77
 
77
78
  element.children.each_with_object(result) do |child, hash|
78
- value = child.text? ? child.text : parse_element(child)
79
-
80
- hash[child.unprefixed_name] = if hash[child.unprefixed_name]
81
- [hash[child.unprefixed_name], value].flatten
79
+ attr = klass.attribute_for_child(child.name, format) if klass&.<= Serialize
80
+
81
+ value = if child.text?
82
+ child.text
83
+ elsif attr&.raw?
84
+ child.children.map do |c|
85
+ next c.text if c.text?
86
+
87
+ c.to_xml.doc.root.to_xml({})
88
+ end.join
89
+ else
90
+ parse_element(child, attr&.type || klass, format)
91
+ end
92
+
93
+ hash[child.namespaced_name] = if hash[child.namespaced_name]
94
+ [hash[child.namespaced_name], value].flatten
82
95
  else
83
96
  value
84
97
  end
85
98
  end
86
99
 
100
+ result.merge(attributes_hash(element))
101
+ end
102
+
103
+ def attributes_hash(element)
104
+ result = Lutaml::Model::MappingHash.new
105
+
87
106
  element.attributes.each_value do |attr|
88
107
  if attr.unprefixed_name == "schemaLocation"
89
108
  result["__schema_location"] = {
@@ -92,7 +111,7 @@ module Lutaml
92
111
  schema_location: attr.value,
93
112
  }
94
113
  else
95
- result[attr.unprefixed_name] = attr.value
114
+ result[attr.name] = attr.value
96
115
  end
97
116
  end
98
117
 
@@ -231,13 +250,17 @@ module Lutaml
231
250
  mapper_class ? mapper_class.mappings_for(:xml).mixed_content? : false
232
251
  end
233
252
 
234
- def build_namespace_attributes(klass, processed = {})
253
+ def set_namespace?(rule)
254
+ rule.nil? || !rule.namespace_set? || !rule.namespace.nil?
255
+ end
256
+
257
+ def build_namespace_attributes(klass, processed = {}, options = {})
235
258
  xml_mappings = klass.mappings_for(:xml)
236
259
  attributes = klass.attributes
237
260
 
238
261
  attrs = {}
239
262
 
240
- if xml_mappings.namespace_uri
263
+ if xml_mappings.namespace_uri && set_namespace?(options[:caller_rule])
241
264
  prefixed_name = [
242
265
  "xmlns",
243
266
  xml_mappings.namespace_prefix,
@@ -262,10 +285,10 @@ module Lutaml
262
285
  next unless type
263
286
 
264
287
  if type <= Lutaml::Model::Serialize
265
- attrs = attrs.merge(build_namespace_attributes(type, processed))
288
+ attrs = attrs.merge(build_namespace_attributes(type, processed, { caller_rule: mapping_rule }))
266
289
  end
267
290
 
268
- if mapping_rule.namespace
291
+ if mapping_rule.namespace && mapping_rule.prefix && mapping_rule.name != "lang"
269
292
  attrs["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
270
293
  end
271
294
  end
@@ -274,23 +297,31 @@ module Lutaml
274
297
  end
275
298
 
276
299
  def build_attributes(element, xml_mapping, options = {})
277
- attrs = namespace_attributes(xml_mapping)
300
+ attrs = if options.fetch(:namespace_set, true)
301
+ namespace_attributes(xml_mapping)
302
+ else
303
+ {}
304
+ end
305
+
306
+ if element.respond_to?(:schema_location) && element.schema_location
307
+ attrs.merge!(element.schema_location.to_xml_attributes)
308
+ end
278
309
 
279
310
  xml_mapping.attributes.each_with_object(attrs) do |mapping_rule, hash|
280
311
  next if options[:except]&.include?(mapping_rule.to)
281
312
  next if mapping_rule.custom_methods[:to]
282
313
 
283
- if mapping_rule.namespace
314
+ if mapping_rule.namespace && mapping_rule.prefix && mapping_rule.name != "lang"
284
315
  hash["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
285
316
  end
286
317
 
287
- hash[mapping_rule.prefixed_name] = element.send(mapping_rule.to)
318
+ hash[mapping_rule.prefixed_name] = mapping_rule.to_value_for(element)
288
319
  end
289
320
 
290
321
  xml_mapping.elements.each_with_object(attrs) do |mapping_rule, hash|
291
322
  next if options[:except]&.include?(mapping_rule.to)
292
323
 
293
- if mapping_rule.namespace
324
+ if mapping_rule.namespace && mapping_rule.prefix
294
325
  hash["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
295
326
  end
296
327
  end
@@ -16,7 +16,8 @@ module Lutaml
16
16
  children = [],
17
17
  text = nil,
18
18
  parent_document: nil,
19
- namespace_prefix: nil
19
+ namespace_prefix: nil,
20
+ default_namespace: nil
20
21
  )
21
22
  @name = extract_name(name)
22
23
  @namespace_prefix = namespace_prefix || extract_namespace_prefix(name)
@@ -24,11 +25,20 @@ module Lutaml
24
25
  @children = children
25
26
  @text = text
26
27
  @parent_document = parent_document
28
+ @default_namespace = default_namespace
27
29
  end
28
30
 
29
31
  def name
30
- if namespace_prefix
31
- "#{namespace_prefix}:#{@name}"
32
+ return @name unless namespace_prefix
33
+
34
+ "#{namespace_prefix}:#{@name}"
35
+ end
36
+
37
+ def namespaced_name
38
+ if namespaces[namespace_prefix] && !text?
39
+ "#{namespaces[namespace_prefix].uri}:#{@name}"
40
+ elsif @default_namespace && !text?
41
+ "#{@default_namespace}:#{name}"
32
42
  else
33
43
  @name
34
44
  end
@@ -6,7 +6,8 @@ module Lutaml
6
6
  attr_reader :root_element,
7
7
  :namespace_uri,
8
8
  :namespace_prefix,
9
- :mixed_content
9
+ :mixed_content,
10
+ :ordered
10
11
 
11
12
  def initialize
12
13
  @elements = {}
@@ -16,10 +17,12 @@ module Lutaml
16
17
  end
17
18
 
18
19
  alias mixed_content? mixed_content
20
+ alias ordered? ordered
19
21
 
20
- def root(name, mixed: false)
22
+ def root(name, mixed: false, ordered: false)
21
23
  @root_element = name
22
24
  @mixed_content = mixed
25
+ @ordered = ordered || mixed # mixed contenet will always be ordered
23
26
  end
24
27
 
25
28
  def prefixed_root
@@ -49,17 +52,19 @@ module Lutaml
49
52
  )
50
53
  validate!(name, to, with)
51
54
 
52
- @elements[name] = XmlMappingRule.new(
55
+ rule = XmlMappingRule.new(
53
56
  name,
54
57
  to: to,
55
58
  render_nil: render_nil,
56
59
  with: with,
57
60
  delegate: delegate,
58
61
  namespace: namespace,
62
+ default_namespace: namespace_uri,
59
63
  prefix: prefix,
60
64
  namespace_set: namespace_set != false,
61
65
  prefix_set: prefix_set != false,
62
66
  )
67
+ @elements[rule.namespaced_name] = rule
63
68
  end
64
69
 
65
70
  def map_attribute(
@@ -75,7 +80,7 @@ module Lutaml
75
80
  )
76
81
  validate!(name, to, with)
77
82
 
78
- @attributes[name] = XmlMappingRule.new(
83
+ rule = XmlMappingRule.new(
79
84
  name,
80
85
  to: to,
81
86
  render_nil: render_nil,
@@ -83,9 +88,11 @@ module Lutaml
83
88
  delegate: delegate,
84
89
  namespace: namespace,
85
90
  prefix: prefix,
91
+ default_namespace: namespace_uri,
86
92
  namespace_set: namespace_set != false,
87
93
  prefix_set: prefix_set != false,
88
94
  )
95
+ @attributes[rule.namespaced_name] = rule
89
96
  end
90
97
 
91
98
  # rubocop:enable Metrics/ParameterLists
@@ -15,7 +15,8 @@ module Lutaml
15
15
  prefix: nil,
16
16
  mixed_content: false,
17
17
  namespace_set: false,
18
- prefix_set: false
18
+ prefix_set: false,
19
+ default_namespace: nil
19
20
  )
20
21
  super(
21
22
  name,
@@ -26,6 +27,7 @@ module Lutaml
26
27
  mixed_content: mixed_content,
27
28
  namespace_set: namespace_set,
28
29
  prefix_set: prefix_set,
30
+ default_namespace: default_namespace
29
31
  )
30
32
 
31
33
  @namespace = if namespace.to_s == "inherit"
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.11
4
+ version: 0.3.13
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-04 00:00:00.000000000 Z
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor