lutaml-model 0.3.28 → 0.3.30

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: 7fbf76c4bb8fbe07fdaed6235a5e8edcd98dc17ace1d322d0e9a36c7c4a59aef
4
- data.tar.gz: f63bf29850309ab1250e2713e62fd6ef624ad5c13a824dc6e7822dec77f75369
3
+ metadata.gz: cca2f0b92a3e71807ed2201909e02ea5877dc1468c34c62d887d523962e63968
4
+ data.tar.gz: 56fe25dc8f9229d2bcabe1315c88f0f7d8fb3a3ca5f01b78b0e6494fb65ebc75
5
5
  SHA512:
6
- metadata.gz: 58b261437656342dc5894e25dcde477f680e72b6eebd0ae6771a5d97f0212442ae5dab446d0e182f5a4a712516b8781a0849bdcb1fa2ee1fbc831ecf9dc33695
7
- data.tar.gz: 0af5c64461b6e9f5ab6d67b18ebe81e19db49123b4241b201c786b1632b567290ab55288f7047e01e3c5938316d7e93b8aca511f6f4a3f3759f1d4575fe758ae
6
+ metadata.gz: a6d19950a00e397146f8a8cfc8eeeb0e3c965f9fb7f5cb3bb5518cf636505f31ec72750552385b533d410eec51c6e325d0d57070fca52189ff00a48c8380c156
7
+ data.tar.gz: b7d55249da057ffe7f222c997ae4f628c7dd5acdeee9d7a1a5919f7f6d034ac5342b961696797029233dcd931a7db82be67f00f89a5b78463c3a7c101fbc3e4f
@@ -0,0 +1,15 @@
1
+ {
2
+ "repo": [
3
+ "lutaml/genericode",
4
+ "lutaml/ogc-gml",
5
+ "metanorma/modspec-ruby",
6
+ "metanorma/rfcxml",
7
+ "metanorma/niso-jats",
8
+ "metanorma/sts-ruby",
9
+ "lutaml/metaschema",
10
+ "glossarist/termium",
11
+ "lutaml/oasis-etm",
12
+ "lutaml/ali",
13
+ "lutaml/reqif"
14
+ ]
15
+ }
@@ -0,0 +1,14 @@
1
+ name: dependent-gems-test
2
+
3
+ on:
4
+ push:
5
+ branches: [ main ]
6
+ tags: [ v* ]
7
+ pull_request:
8
+ workflow_dispatch:
9
+ repository_dispatch:
10
+ types: [ release-passed ]
11
+
12
+ jobs:
13
+ rake:
14
+ uses: metanorma/ci/.github/workflows/dependent-rake.yml@main
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-11-11 10:52:30 UTC using RuboCop version 1.68.0.
3
+ # on 2024-12-03 11:13:42 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: 132
9
+ # Offense count: 224
10
10
  # This cop supports safe autocorrection (--autocorrect).
11
11
  # Configuration parameters: Max, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
12
12
  # URISchemes: http, https
@@ -26,13 +26,12 @@ Lint/ConstantDefinitionInBlock:
26
26
  - 'spec/lutaml/model/validation_spec.rb'
27
27
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
28
28
 
29
- # Offense count: 2
29
+ # Offense count: 1
30
30
  Lint/DuplicateMethods:
31
31
  Exclude:
32
- - 'lib/lutaml/model/attribute.rb'
33
32
  - 'lib/lutaml/model/type/float.rb'
34
33
 
35
- # Offense count: 36
34
+ # Offense count: 37
36
35
  # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes, Max.
37
36
  Metrics/AbcSize:
38
37
  Exclude:
@@ -45,15 +44,16 @@ Metrics/AbcSize:
45
44
  - 'lib/lutaml/model/xml_adapter/nokogiri_adapter.rb'
46
45
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
47
46
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
47
+ - 'lib/lutaml/model/xml_mapping.rb'
48
48
  - 'lib/lutaml/model/xml_mapping_rule.rb'
49
49
 
50
50
  # Offense count: 6
51
51
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
52
52
  # AllowedMethods: refine
53
53
  Metrics/BlockLength:
54
- Max: 47
54
+ Max: 46
55
55
 
56
- # Offense count: 26
56
+ # Offense count: 28
57
57
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
58
58
  Metrics/CyclomaticComplexity:
59
59
  Exclude:
@@ -65,7 +65,7 @@ Metrics/CyclomaticComplexity:
65
65
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
66
66
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
67
67
 
68
- # Offense count: 53
68
+ # Offense count: 54
69
69
  # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
70
70
  Metrics/MethodLength:
71
71
  Max: 46
@@ -75,7 +75,7 @@ Metrics/MethodLength:
75
75
  Metrics/ParameterLists:
76
76
  Max: 14
77
77
 
78
- # Offense count: 23
78
+ # Offense count: 25
79
79
  # Configuration parameters: AllowedMethods, AllowedPatterns, Max.
80
80
  Metrics/PerceivedComplexity:
81
81
  Exclude:
@@ -87,7 +87,7 @@ Metrics/PerceivedComplexity:
87
87
  - 'lib/lutaml/model/xml_adapter/ox_adapter.rb'
88
88
  - 'lib/lutaml/model/xml_adapter/xml_document.rb'
89
89
 
90
- # Offense count: 7
90
+ # Offense count: 8
91
91
  # Configuration parameters: Prefixes, AllowedPatterns.
92
92
  # Prefixes: when, with, without
93
93
  RSpec/ContextWording:
@@ -97,7 +97,15 @@ RSpec/ContextWording:
97
97
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
98
98
  - 'spec/lutaml/model/xml_mapping_spec.rb'
99
99
 
100
- # Offense count: 117
100
+ # Offense count: 1
101
+ # This cop supports unsafe autocorrection (--autocorrect-all).
102
+ # Configuration parameters: SkipBlocks, EnforcedStyle, OnlyStaticConstants.
103
+ # SupportedStyles: described_class, explicit
104
+ RSpec/DescribedClass:
105
+ Exclude:
106
+ - 'spec/lutaml/model/xml_mapping_spec.rb'
107
+
108
+ # Offense count: 133
101
109
  # Configuration parameters: CountAsOne.
102
110
  RSpec/ExampleLength:
103
111
  Max: 54
@@ -127,16 +135,16 @@ RSpec/MultipleDescribes:
127
135
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
128
136
  - 'spec/lutaml/model/xml_adapter_spec.rb'
129
137
 
130
- # Offense count: 149
138
+ # Offense count: 157
131
139
  RSpec/MultipleExpectations:
132
140
  Max: 14
133
141
 
134
- # Offense count: 18
142
+ # Offense count: 24
135
143
  # Configuration parameters: AllowSubject.
136
144
  RSpec/MultipleMemoizedHelpers:
137
145
  Max: 9
138
146
 
139
- # Offense count: 9
147
+ # Offense count: 15
140
148
  # Configuration parameters: AllowedGroups.
141
149
  RSpec/NestedGroups:
142
150
  Max: 4
@@ -154,10 +162,9 @@ RSpec/PendingWithoutReason:
154
162
  - 'spec/lutaml/model/xml_adapter/xml_namespace_spec.rb'
155
163
  - 'spec/lutaml/model/xml_adapter_spec.rb'
156
164
 
157
- # Offense count: 2
165
+ # Offense count: 1
158
166
  RSpec/RemoveConst:
159
167
  Exclude:
160
- - 'spec/lutaml/model/type/decimal_spec.rb'
161
168
  - 'spec/lutaml/model/type_spec.rb'
162
169
 
163
170
  # Offense count: 2
data/README.adoc CHANGED
@@ -938,8 +938,7 @@ This includes:
938
938
  * attributes
939
939
  * text nodes
940
940
 
941
- The `map_all` tag is **exclusive** and cannot be combined with other mappings
942
- (`map_element`, `map_attribute`, `map_content`) for the same element, ensuring
941
+ The `map_all` tag is **exclusive** and cannot be combined with other mappings (`map_element`, `map_content`) except for `map_attribute` for the same element, ensuring
943
942
  it captures the entire inner XML content.
944
943
 
945
944
  NOTE: An error is raised if `map_all` is defined alongside any other mapping in
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module JsonAdapter
8
8
  # Base class for JSON documents
9
9
  class JsonDocument < JsonObject
10
- def self.parse(json)
10
+ def self.parse(json, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module JsonAdapter
7
7
  class MultiJsonAdapter < JsonDocument
8
- def self.parse(json)
8
+ def self.parse(json, _options = {})
9
9
  data = MultiJson.load(json)
10
10
  new(data)
11
11
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module JsonAdapter
7
7
  class StandardJsonAdapter < JsonDocument
8
- def self.parse(json)
8
+ def self.parse(json, _options = {})
9
9
  JSON.parse(json, create_additions: false)
10
10
  end
11
11
 
@@ -51,6 +51,7 @@ module Lutaml
51
51
  Utils.add_boolean_accessor_if_not_defined(klass, :ordered)
52
52
  Utils.add_boolean_accessor_if_not_defined(klass, :mixed)
53
53
  Utils.add_accessor_if_not_defined(klass, :element_order)
54
+ Utils.add_accessor_if_not_defined(klass, :encoding)
54
55
 
55
56
  Utils.add_method_if_not_defined(klass,
56
57
  :using_default_for) do |attribute_name|
@@ -101,23 +102,22 @@ module Lutaml
101
102
  end
102
103
  end
103
104
 
104
- define_method(:"from_#{format}") do |data|
105
+ define_method(:"from_#{format}") do |data, options = {}|
105
106
  adapter = Lutaml::Model::Config.send(:"#{format}_adapter")
106
107
 
107
- doc = adapter.parse(data)
108
- public_send(:"of_#{format}", doc)
108
+ doc = adapter.parse(data, options)
109
+ public_send(:"of_#{format}", doc, options)
109
110
  end
110
111
 
111
- define_method(:"of_#{format}") do |doc|
112
+ define_method(:"of_#{format}") do |doc, options = {}|
112
113
  if doc.is_a?(Array)
113
- return doc.map do |item|
114
- send(:"of_#{format}", item)
115
- end
114
+ return doc.map { |item| send(:"of_#{format}", item) }
116
115
  end
117
116
 
118
117
  if format == :xml
119
118
  doc_hash = doc.parse_element(doc.root, self, :xml)
120
- apply_mappings(doc_hash, format)
119
+ options[:encoding] = doc.encoding
120
+ apply_mappings(doc_hash, format, options)
121
121
  else
122
122
  apply_mappings(doc.to_h, format)
123
123
  end
@@ -315,6 +315,7 @@ module Lutaml
315
315
  end
316
316
 
317
317
  def apply_xml_mapping(doc, instance, options = {})
318
+ instance.encoding = options[:encoding]
318
319
  return instance unless doc
319
320
 
320
321
  if options[:default_namespace].nil?
@@ -347,6 +348,8 @@ module Lutaml
347
348
  mappings.each do |rule|
348
349
  raise "Attribute '#{rule.to}' not found in #{self}" unless valid_rule?(rule)
349
350
 
351
+ attr = attribute_for_rule(rule)
352
+
350
353
  value = if rule.raw_mapping?
351
354
  doc.node.inner_xml
352
355
  elsif rule.content_mapping?
@@ -355,10 +358,10 @@ module Lutaml
355
358
  doc.fetch(rule.namespaced_name(options[:default_namespace]))
356
359
  else
357
360
  defaults_used << rule.to
358
- rule.to_value_for(instance)
361
+ attr&.default || rule.to_value_for(instance)
359
362
  end
360
363
 
361
- value = normalize_xml_value(value, rule, options)
364
+ value = normalize_xml_value(value, rule, attr, options)
362
365
  rule.deserialize(instance, value, attributes, self)
363
366
  end
364
367
 
@@ -399,9 +402,7 @@ module Lutaml
399
402
  instance
400
403
  end
401
404
 
402
- def normalize_xml_value(value, rule, options = {})
403
- attr = attribute_for_rule(rule)
404
-
405
+ def normalize_xml_value(value, rule, attr, options = {})
405
406
  value = [value].compact if attr&.collection? && !value.is_a?(Array)
406
407
 
407
408
  value = if value.is_a?(Array)
@@ -459,7 +460,7 @@ module Lutaml
459
460
  end
460
461
  end
461
462
 
462
- attr_accessor :element_order, :schema_location
463
+ attr_accessor :element_order, :schema_location, :encoding
463
464
  attr_writer :ordered, :mixed
464
465
 
465
466
  def initialize(attrs = {})
@@ -548,6 +549,7 @@ module Lutaml
548
549
  options)
549
550
  end
550
551
 
552
+ options[:parse_encoding] = encoding if encoding
551
553
  adapter.new(representation).public_send(:"to_#{format}", options)
552
554
  end
553
555
  end
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module TomlAdapter
8
8
  # Base class for TOML documents
9
9
  class TomlDocument < TomlObject
10
- def self.parse(toml)
10
+ def self.parse(toml, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module TomlAdapter
7
7
  class TomlRbAdapter < TomlDocument
8
- def self.parse(toml)
8
+ def self.parse(toml, _options = {})
9
9
  data = TomlRB.parse(toml)
10
10
  new(data)
11
11
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module TomlAdapter
7
7
  class TomlibAdapter < TomlDocument
8
- def self.parse(toml)
8
+ def self.parse(toml, _options = {})
9
9
  data = Tomlib.load(toml)
10
10
  new(data)
11
11
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lutaml
4
4
  module Model
5
- VERSION = "0.3.28"
5
+ VERSION = "0.3.30"
6
6
  end
7
7
  end
@@ -51,6 +51,16 @@ module Lutaml
51
51
  end
52
52
  end
53
53
 
54
+ def add_xml_fragment(element, content)
55
+ if element.is_a?(self.class)
56
+ element = element.xml.parent
57
+ end
58
+
59
+ fragment = ::Nokogiri::XML::DocumentFragment.parse(content)
60
+
61
+ element.add_child(fragment)
62
+ end
63
+
54
64
  def add_text(element, text, cdata: false)
55
65
  return add_cdata(element, text) if cdata
56
66
 
@@ -66,10 +66,14 @@ module Lutaml
66
66
  xml.text(text)
67
67
  end
68
68
 
69
+ def add_xml_fragment(element, content)
70
+ element.raw(content)
71
+ end
72
+
69
73
  def add_text(element, text, cdata: false)
70
74
  return element.cdata(text) if cdata
71
75
 
72
- element << text
76
+ element.text(text)
73
77
  end
74
78
 
75
79
  def add_cdata(element, value)
@@ -6,10 +6,10 @@ module Lutaml
6
6
  module Model
7
7
  module XmlAdapter
8
8
  class NokogiriAdapter < XmlDocument
9
- def self.parse(xml)
10
- parsed = Nokogiri::XML(xml)
9
+ def self.parse(xml, options = {})
10
+ parsed = Nokogiri::XML(xml, nil, options[:encoding])
11
11
  root = NokogiriElement.new(parsed.root)
12
- new(root)
12
+ new(root, parsed.encoding)
13
13
  end
14
14
 
15
15
  def to_xml(options = {})
@@ -17,6 +17,8 @@ module Lutaml
17
17
 
18
18
  if options.key?(:encoding)
19
19
  builder_options[:encoding] = options[:encoding] unless options[:encoding].nil?
20
+ elsif options.key?(:parse_encoding)
21
+ builder_options[:encoding] = options[:parse_encoding]
20
22
  else
21
23
  builder_options[:encoding] = "UTF-8"
22
24
  end
@@ -5,7 +5,7 @@ module Lutaml
5
5
  module Model
6
6
  module XmlAdapter
7
7
  class OgaAdapter < XmlDocument
8
- def self.parse(xml)
8
+ def self.parse(xml, _options = {})
9
9
  parsed = Oga.parse_xml(xml)
10
10
  root = OgaElement.new(parsed)
11
11
  new(root)
@@ -6,23 +6,28 @@ module Lutaml
6
6
  module Model
7
7
  module XmlAdapter
8
8
  class OxAdapter < XmlDocument
9
- def self.parse(xml)
9
+ def self.parse(xml, options = {})
10
+ Ox.default_options = Ox.default_options.merge(encoding: options[:encoding] || "UTF-8")
11
+
10
12
  parsed = Ox.parse(xml)
11
13
  root = OxElement.new(parsed)
12
- new(root)
14
+ new(root, Ox.default_options[:encoding])
13
15
  end
14
16
 
15
17
  def to_xml(options = {})
16
- builder = Builder::Ox.build
17
18
  builder_options = { version: options[:version] }
18
19
 
19
- if options.key?(:encoding)
20
- builder_options[:encoding] = options[:encoding] unless options[:encoding].nil?
21
- else
22
- builder_options[:encoding] = "UTF-8"
23
- end
20
+ builder_options[:encoding] = if options.key?(:encoding)
21
+ options[:encoding]
22
+ elsif options.key?(:parse_encoding)
23
+ options[:parse_encoding]
24
+ else
25
+ "UTF-8"
26
+ end
27
+
28
+ builder = Builder::Ox.build
29
+ builder.xml.instruct(:xml, encoding: options[:parse_encoding])
24
30
 
25
- builder.xml.instruct(:xml, builder_options)
26
31
  if @root.is_a?(Lutaml::Model::XmlAdapter::OxElement)
27
32
  @root.build_xml(builder)
28
33
  elsif ordered?(@root, options)
@@ -34,7 +39,12 @@ module Lutaml
34
39
  end
35
40
 
36
41
  xml_data = builder.xml.to_s
37
- options[:declaration] ? xml_data : xml_data.sub(/\A<\?xml[^>]*\?>\n?/, "")
42
+ if builder_options[:encoding] && xml_data.valid_encoding?
43
+ xml_data = xml_data.encode(builder_options[:encoding])
44
+ end
45
+
46
+ stripped_data = xml_data.lines.drop(1).join
47
+ options[:declaration] ? declaration(options) + stripped_data : stripped_data
38
48
  end
39
49
 
40
50
  private
@@ -145,6 +155,11 @@ module Lutaml
145
155
  build_xml.xml.to_s
146
156
  end
147
157
 
158
+ def inner_xml
159
+ # Ox builder by default, adds a newline at the end, so `chomp` is used
160
+ children.map { |child| child.to_xml.chomp }.join
161
+ end
162
+
148
163
  def build_xml(builder = nil)
149
164
  builder ||= Builder::Ox.build
150
165
  attrs = build_attributes(self)
@@ -7,13 +7,14 @@ module Lutaml
7
7
  module Model
8
8
  module XmlAdapter
9
9
  class XmlDocument
10
- attr_reader :root
10
+ attr_reader :root, :encoding
11
11
 
12
- def initialize(root)
12
+ def initialize(root, encoding = nil)
13
13
  @root = root
14
+ @encoding = encoding
14
15
  end
15
16
 
16
- def self.parse(xml)
17
+ def self.parse(xml, _options = {})
17
18
  raise NotImplementedError, "Subclasses must implement `parse`."
18
19
  end
19
20
 
@@ -150,6 +151,8 @@ module Lutaml
150
151
  value,
151
152
  options.merge({ rule: rule, attribute: attribute }),
152
153
  )
154
+ elsif rule.raw_mapping?
155
+ xml.add_xml_fragment(xml, value)
153
156
  elsif rule.prefix_set?
154
157
  xml.create_and_add_element(rule.name, prefix: prefix) do
155
158
  add_value(xml, value, attribute, cdata: rule.cdata)
@@ -186,10 +189,6 @@ module Lutaml
186
189
  attributes = build_attributes(element,
187
190
  xml_mapping, options).merge(attributes)&.compact
188
191
 
189
- if element.respond_to?(:schema_location) && element.schema_location
190
- attributes.merge!(element.schema_location.to_xml_attributes)
191
- end
192
-
193
192
  prefix = if options.key?(:namespace_prefix)
194
193
  options[:namespace_prefix]
195
194
  elsif xml_mapping.namespace_prefix
@@ -210,7 +209,8 @@ module Lutaml
210
209
  xml)
211
210
  end
212
211
 
213
- xml_mapping.elements.each do |element_rule|
212
+ mappings = xml_mapping.elements + [xml_mapping.raw_mapping].compact
213
+ mappings.each do |element_rule|
214
214
  attribute_def = attribute_definition_for(element, element_rule,
215
215
  mapper_class: mapper_class)
216
216
 
@@ -234,20 +234,9 @@ module Lutaml
234
234
 
235
235
  process_content_mapping(element, xml_mapping.content_mapping,
236
236
  prefixed_xml)
237
-
238
- process_raw_mapping(element, xml_mapping.raw_mapping, prefixed_xml)
239
237
  end
240
238
  end
241
239
 
242
- def process_raw_mapping(element, rule, xml)
243
- return unless rule
244
-
245
- value = attribute_value_for(element, rule)
246
- return unless render_element?(rule, element, value)
247
-
248
- xml.add_text(xml, value, cdata: rule.cdata)
249
- end
250
-
251
240
  def process_content_mapping(element, content_rule, xml)
252
241
  return unless content_rule
253
242
 
@@ -343,7 +332,7 @@ module Lutaml
343
332
  {}
344
333
  end
345
334
 
346
- if element.respond_to?(:schema_location) && element.schema_location
335
+ if element.respond_to?(:schema_location) && element.schema_location && !options[:except]&.include?(:schema_location)
347
336
  attrs.merge!(element.schema_location.to_xml_attributes)
348
337
  end
349
338
 
@@ -355,10 +344,9 @@ module Lutaml
355
344
  hash["xmlns:#{mapping_rule.prefix}"] = mapping_rule.namespace
356
345
  end
357
346
 
358
- if render_element?(mapping_rule, element,
359
- mapping_rule.to_value_for(element))
360
- hash[mapping_rule.prefixed_name] =
361
- mapping_rule.to_value_for(element)
347
+ value = mapping_rule.to_value_for(element)
348
+ if render_element?(mapping_rule, element, value)
349
+ hash[mapping_rule.prefixed_name] = value ? value.to_s : value
362
350
  end
363
351
  end
364
352
 
@@ -3,6 +3,13 @@ require_relative "xml_mapping_rule"
3
3
  module Lutaml
4
4
  module Model
5
5
  class XmlMapping
6
+ TYPES = {
7
+ attribute: :map_attribute,
8
+ element: :map_element,
9
+ content: :map_content,
10
+ all_content: :map_all,
11
+ }.freeze
12
+
6
13
  attr_reader :root_element,
7
14
  :namespace_uri,
8
15
  :namespace_prefix,
@@ -53,7 +60,7 @@ module Lutaml
53
60
  prefix: (prefix_set = false
54
61
  nil)
55
62
  )
56
- validate!(name, to, with)
63
+ validate!(name, to, with, type: TYPES[:element])
57
64
 
58
65
  rule = XmlMappingRule.new(
59
66
  name,
@@ -84,7 +91,7 @@ module Lutaml
84
91
  prefix: (prefix_set = false
85
92
  nil)
86
93
  )
87
- validate!(name, to, with)
94
+ validate!(name, to, with, type: TYPES[:attribute])
88
95
 
89
96
  rule = XmlMappingRule.new(
90
97
  name,
@@ -114,7 +121,7 @@ module Lutaml
114
121
  mixed: false,
115
122
  cdata: false
116
123
  )
117
- validate!("content", to, with)
124
+ validate!("content", to, with, type: TYPES[:content])
118
125
 
119
126
  @content_mapping = XmlMappingRule.new(
120
127
  nil,
@@ -139,7 +146,7 @@ module Lutaml
139
146
  prefix: (prefix_set = false
140
147
  nil)
141
148
  )
142
- validate!("__raw_mapping", to, with)
149
+ validate!("__raw_mapping", to, with, type: TYPES[:all_content])
143
150
 
144
151
  rule = XmlMappingRule.new(
145
152
  "__raw_mapping",
@@ -158,8 +165,8 @@ module Lutaml
158
165
  @raw_mapping = rule
159
166
  end
160
167
 
161
- def validate!(key, to, with)
162
- validate_mappings!(key)
168
+ def validate!(key, to, with, type: nil)
169
+ validate_mappings!(type)
163
170
 
164
171
  if to.nil? && with.empty?
165
172
  msg = ":to or :with argument is required for mapping '#{key}'"
@@ -172,13 +179,14 @@ module Lutaml
172
179
  end
173
180
  end
174
181
 
175
- def validate_mappings!(key)
176
- unless @raw_mapping.nil?
177
- raise StandardError, "no other mappings are allowed with map_all"
182
+ def validate_mappings!(type)
183
+ if !@raw_mapping.nil? && type != TYPES[:attribute]
184
+ raise StandardError, "#{type} is not allowed, only #{TYPES[:attribute]} " \
185
+ "is allowed with #{TYPES[:all_content]}"
178
186
  end
179
187
 
180
- if !mappings.empty? && key == "__raw_mapping"
181
- raise StandardError, "map_all is not allowed with other mappings"
188
+ if !(elements.empty? && content_mapping.nil?) && type == TYPES[:all_content]
189
+ raise StandardError, "#{TYPES[:all_content]} is not allowed with other mappings"
182
190
  end
183
191
  end
184
192
 
@@ -14,7 +14,7 @@ module Lutaml
14
14
  PERMITTED_CLASSES_BASE
15
15
  end.freeze
16
16
 
17
- def self.parse(yaml)
17
+ def self.parse(yaml, _options = {})
18
18
  YAML.safe_load(yaml, permitted_classes: PERMITTED_CLASSES)
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ module Lutaml
7
7
  module YamlAdapter
8
8
  # Base class for YAML documents
9
9
  class YamlDocument < YamlObject
10
- def self.parse(yaml)
10
+ def self.parse(yaml, _options = {})
11
11
  raise NotImplementedError, "Subclasses must implement `parse`."
12
12
  end
13
13
 
@@ -0,0 +1,5 @@
1
+ <note>
2
+ <to>Jos�</to>
3
+ <from>M�ller</from>
4
+ <heading>Reminder</heading>
5
+ </note>