lutaml-model 0.3.2 → 0.3.3

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: f9a3608f755616317667038ebd8f71368c23dcf935a7b07ad33d8efd1fa1df23
4
- data.tar.gz: 9a69a3a03c401fa4a0eff423315dc979e4f5b87c28b28bf4b4d10b7f118b6a77
3
+ metadata.gz: c1c49d91f74f3454b6a0e2aaf34bfef142630fa77e98a509535b53b156f603e7
4
+ data.tar.gz: 12880e7b701bf68c2a77efad6148daeac040a1956f1f1e1a0d790657c79f346c
5
5
  SHA512:
6
- metadata.gz: 612d55df7ef46e1266b6d6e2fa4a6e451862252895a8f8b66b0a1f42bb96d289fc28c160ee1e2d609bc4ebc4ce8db00d14a1fca3061e8465a2f867403f5672b0
7
- data.tar.gz: 20235f85e8719fceb5a048dfcebf9f80e0a1c3c2d3bc2f6779fd0e1480d77c989adcc1bdedc661e440dbd861e7cf04682321626693281ac9c21920d45310f6b6
6
+ metadata.gz: '08020dbbadaea322601ce9c0536cf3a49aeaa44679d8caf278995d0f7b1c41ba12761897db7f54390bb1288c84ccedc6a0a45bee980926fecca18927a17c8de7'
7
+ data.tar.gz: 363806235f0d4308f127d84590d1b2d2bf2af5adafd27974fa6a8600f5e67afac6efc27f3ee810eea95265d6764b6f4538672f18c5c9a3e243c31f236595fe21
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-08-15 09:04:06 UTC using RuboCop version 1.65.1.
3
+ # on 2024-08-16 03:28:27 UTC using RuboCop version 1.65.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
@@ -14,7 +14,7 @@ Gemspec/RequireMFA:
14
14
  Exclude:
15
15
  - 'lutaml-model.gemspec'
16
16
 
17
- # Offense count: 28
17
+ # Offense count: 32
18
18
  # This cop supports safe autocorrection (--autocorrect).
19
19
  # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
20
20
  # URISchemes: http, https
@@ -26,6 +26,7 @@ Layout/LineLength:
26
26
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
27
27
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
28
28
  - 'spec/lutaml/model/delegation_spec.rb'
29
+ - 'spec/lutaml/model/serializable_spec.rb'
29
30
 
30
31
  # Offense count: 20
31
32
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
@@ -82,7 +83,7 @@ RSpec/ContextWording:
82
83
  - 'spec/lutaml/model/xml_adapter/oga_adapter_spec.rb'
83
84
  - 'spec/lutaml/model/xml_adapter/ox_adapter_spec.rb'
84
85
 
85
- # Offense count: 63
86
+ # Offense count: 64
86
87
  # Configuration parameters: CountAsOne.
87
88
  RSpec/ExampleLength:
88
89
  Max: 35
data/README.adoc CHANGED
@@ -401,6 +401,42 @@ end
401
401
  ----
402
402
  ====
403
403
 
404
+ If an element is mapped to a model object with the XML `root` tag name set, the
405
+ mapped tag name will be used as the root name, overriding the root name.
406
+
407
+ .The mapped tag name is used as the root name
408
+ [example]
409
+ ====
410
+ [source,ruby]
411
+ ----
412
+ class RecordDate < Lutaml::Model::Serializable
413
+ attribute :content, :string
414
+
415
+ xml do
416
+ root "recordDate"
417
+ map_content to: :content
418
+ end
419
+ end
420
+
421
+ class OriginInfo < Lutaml::Model::Serializable
422
+ attribute :date_issued, RecordDate, collection: true
423
+
424
+ xml do
425
+ root "originInfo"
426
+ map_element "dateIssued", to: :date_issued
427
+ end
428
+ end
429
+ ----
430
+
431
+ [source,ruby]
432
+ ----
433
+ > RecordDate.new(date: "2021-01-01").to_xml
434
+ > #<recordDate>2021-01-01</recordDate>
435
+ > OriginInfo.new(date_issued: [RecordDate.new(date: "2021-01-01")]).to_xml
436
+ > #<originInfo><dateIssued>2021-01-01</dateIssued></originInfo>
437
+ ----
438
+ ====
439
+
404
440
  ==== Mapping attributes
405
441
 
406
442
  The `map_attribute` method maps an XML attribute to a data model attribute.
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.3.2"
5
+ VERSION = "0.3.3"
6
6
  end
7
7
  end
@@ -48,7 +48,8 @@ module Lutaml
48
48
  xml
49
49
  end
50
50
 
51
- prefixed_xml.public_send(xml_mapping.root_element, attributes) do
51
+ tag_name = options[:tag_name] || xml_mapping.root_element
52
+ prefixed_xml.public_send(tag_name, attributes) do
52
53
  if options.key?(:namespace_prefix) && !options[:namespace_prefix]
53
54
  xml.parent.namespace = nil
54
55
  end
@@ -94,7 +95,8 @@ module Lutaml
94
95
  xml
95
96
  end
96
97
 
97
- prefixed_xml.public_send(xml_mapping.root_element, attributes) do
98
+ tag_name = options[:tag_name] || xml_mapping.root_element
99
+ prefixed_xml.public_send(tag_name, attributes) do
98
100
  if options.key?(:namespace_prefix) && !options[:namespace_prefix]
99
101
  xml.parent.namespace = nil
100
102
  end
@@ -36,12 +36,13 @@ module Lutaml
36
36
 
37
37
  attributes = build_attributes(element, xml_mapping).compact
38
38
 
39
+ tag_name = options[:tag_name] || xml_mapping.root_element
39
40
  prefixed_name = if options.key?(:namespace_prefix)
40
- [options[:namespace_prefix], xml_mapping.root_element].compact.join(":")
41
+ [options[:namespace_prefix], tag_name].compact.join(":")
41
42
  elsif xml_mapping.namespace_prefix
42
- "#{xml_mapping.namespace_prefix}:#{xml_mapping.root_element}"
43
+ "#{xml_mapping.namespace_prefix}:#{tag_name}"
43
44
  else
44
- xml_mapping.root_element
45
+ tag_name
45
46
  end
46
47
 
47
48
  builder.element(prefixed_name, attributes) do |el|
@@ -84,7 +85,8 @@ module Lutaml
84
85
 
85
86
  attributes = build_attributes(element, xml_mapping).compact
86
87
 
87
- builder.element(xml_mapping.root_element, attributes) do |el|
88
+ tag_name = options[:tag_name] || xml_mapping.root_element
89
+ builder.element(tag_name, attributes) do |el|
88
90
  index_hash = {}
89
91
 
90
92
  element.element_order.each do |name|
@@ -60,6 +60,7 @@ module Lutaml
60
60
 
61
61
  options[:namespace_prefix] = rule.prefix if rule&.namespace_set?
62
62
  options[:mixed_content] = rule.mixed_content
63
+ options[:tag_name] = rule.name
63
64
 
64
65
  options[:mapper_class] = attribute&.type if attribute
65
66
 
@@ -9,8 +9,8 @@ module Lutaml
9
9
  :mixed_content
10
10
 
11
11
  def initialize
12
- @elements = []
13
- @attributes = []
12
+ @elements = {}
13
+ @attributes = {}
14
14
  @content_mapping = nil
15
15
  @mixed_content = false
16
16
  end
@@ -47,7 +47,7 @@ module Lutaml
47
47
  prefix: nil,
48
48
  mixed: false
49
49
  )
50
- @elements << XmlMappingRule.new(
50
+ @elements[name] = XmlMappingRule.new(
51
51
  name,
52
52
  to: to,
53
53
  render_nil: render_nil,
@@ -70,7 +70,7 @@ module Lutaml
70
70
  nil),
71
71
  prefix: nil
72
72
  )
73
- @attributes << XmlMappingRule.new(
73
+ @attributes[name] = XmlMappingRule.new(
74
74
  name,
75
75
  to: to,
76
76
  render_nil: render_nil,
@@ -102,11 +102,11 @@ module Lutaml
102
102
  end
103
103
 
104
104
  def elements
105
- @elements
105
+ @elements.values
106
106
  end
107
107
 
108
108
  def attributes
109
- @attributes
109
+ @attributes.values
110
110
  end
111
111
 
112
112
  def content_mapping
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.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-15 00:00:00.000000000 Z
11
+ date: 2024-08-16 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'LutaML creating data models in Ruby
14
14