lutaml-model 0.6.7 → 0.7.2

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.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/dependent-repos-todo.json +7 -0
  3. data/.github/workflows/dependent-repos.json +17 -9
  4. data/.rubocop.yml +1 -1
  5. data/.rubocop_todo.yml +51 -65
  6. data/Gemfile +4 -1
  7. data/README.adoc +5083 -2612
  8. data/RELEASE_NOTES.adoc +346 -0
  9. data/docs/custom_adapters.adoc +144 -0
  10. data/lib/lutaml/model/attribute.rb +101 -16
  11. data/lib/lutaml/model/choice.rb +7 -0
  12. data/lib/lutaml/model/comparable_model.rb +48 -9
  13. data/lib/lutaml/model/config.rb +48 -42
  14. data/lib/lutaml/model/error/collection_count_out_of_range_error.rb +1 -1
  15. data/lib/lutaml/model/error/polymorphic_error.rb +14 -0
  16. data/lib/lutaml/model/error.rb +1 -0
  17. data/lib/lutaml/model/format_registry.rb +41 -0
  18. data/lib/lutaml/model/hash/document.rb +11 -0
  19. data/lib/lutaml/model/hash/mapping.rb +19 -0
  20. data/lib/lutaml/model/hash/mapping_rule.rb +9 -0
  21. data/lib/lutaml/model/hash/standard_adapter.rb +17 -0
  22. data/lib/lutaml/model/hash/transform.rb +8 -0
  23. data/lib/lutaml/model/hash.rb +21 -0
  24. data/lib/lutaml/model/json/document.rb +11 -0
  25. data/lib/lutaml/model/json/mapping.rb +19 -0
  26. data/lib/lutaml/model/json/mapping_rule.rb +9 -0
  27. data/lib/lutaml/model/{json_adapter → json}/multi_json_adapter.rb +4 -5
  28. data/lib/lutaml/model/{json_adapter/standard_json_adapter.rb → json/standard_adapter.rb} +5 -3
  29. data/lib/lutaml/model/json/transform.rb +8 -0
  30. data/lib/lutaml/model/json.rb +21 -0
  31. data/lib/lutaml/model/key_value_document.rb +27 -0
  32. data/lib/lutaml/model/{key_value_mapping.rb → mapping/key_value_mapping.rb} +64 -16
  33. data/lib/lutaml/model/{key_value_mapping_rule.rb → mapping/key_value_mapping_rule.rb} +18 -2
  34. data/lib/lutaml/model/mapping/mapping.rb +13 -0
  35. data/lib/lutaml/model/mapping/mapping_rule.rb +300 -0
  36. data/lib/lutaml/model/schema/xml_compiler.rb +15 -15
  37. data/lib/lutaml/model/sequence.rb +2 -2
  38. data/lib/lutaml/model/serialization_adapter.rb +22 -0
  39. data/lib/lutaml/model/serialize.rb +219 -444
  40. data/lib/lutaml/model/services/logger.rb +54 -0
  41. data/lib/lutaml/model/services/transformer.rb +48 -0
  42. data/lib/lutaml/model/services.rb +2 -0
  43. data/lib/lutaml/model/toml/document.rb +11 -0
  44. data/lib/lutaml/model/toml/mapping.rb +27 -0
  45. data/lib/lutaml/model/toml/mapping_rule.rb +9 -0
  46. data/lib/lutaml/model/{toml_adapter → toml}/toml_rb_adapter.rb +3 -3
  47. data/lib/lutaml/model/toml/tomlib_adapter.rb +19 -0
  48. data/lib/lutaml/model/toml/transform.rb +8 -0
  49. data/lib/lutaml/model/toml.rb +30 -0
  50. data/lib/lutaml/model/transform/key_value_transform.rb +291 -0
  51. data/lib/lutaml/model/transform/xml_transform.rb +239 -0
  52. data/lib/lutaml/model/transform.rb +78 -0
  53. data/lib/lutaml/model/type/date.rb +1 -1
  54. data/lib/lutaml/model/type/date_time.rb +2 -2
  55. data/lib/lutaml/model/type/hash.rb +1 -1
  56. data/lib/lutaml/model/type/time.rb +2 -2
  57. data/lib/lutaml/model/type/time_without_date.rb +2 -2
  58. data/lib/lutaml/model/type/value.rb +6 -9
  59. data/lib/lutaml/model/uninitialized_class.rb +64 -0
  60. data/lib/lutaml/model/utils.rb +44 -0
  61. data/lib/lutaml/model/validation.rb +1 -0
  62. data/lib/lutaml/model/version.rb +1 -1
  63. data/lib/lutaml/model/{xml_adapter → xml}/builder/nokogiri.rb +2 -2
  64. data/lib/lutaml/model/{xml_adapter → xml}/builder/oga.rb +10 -10
  65. data/lib/lutaml/model/{xml_adapter → xml}/builder/ox.rb +1 -1
  66. data/lib/lutaml/model/{xml_adapter/xml_document.rb → xml/document.rb} +41 -21
  67. data/lib/lutaml/model/xml/element.rb +32 -0
  68. data/lib/lutaml/model/xml/mapping.rb +410 -0
  69. data/lib/lutaml/model/xml/mapping_rule.rb +141 -0
  70. data/lib/lutaml/model/xml/nokogiri_adapter.rb +232 -0
  71. data/lib/lutaml/model/{xml_adapter → xml}/oga/document.rb +1 -1
  72. data/lib/lutaml/model/{xml_adapter → xml}/oga/element.rb +3 -1
  73. data/lib/lutaml/model/xml/oga_adapter.rb +171 -0
  74. data/lib/lutaml/model/xml/ox_adapter.rb +215 -0
  75. data/lib/lutaml/model/xml/transform.rb +8 -0
  76. data/lib/lutaml/model/{xml_adapter → xml}/xml_attribute.rb +1 -1
  77. data/lib/lutaml/model/{xml_adapter → xml}/xml_element.rb +23 -10
  78. data/lib/lutaml/model/{xml_adapter → xml}/xml_namespace.rb +1 -1
  79. data/lib/lutaml/model/xml.rb +31 -0
  80. data/lib/lutaml/model/xml_adapter/element.rb +11 -25
  81. data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +6 -223
  82. data/lib/lutaml/model/xml_adapter/oga_adapter.rb +13 -163
  83. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +10 -207
  84. data/lib/lutaml/model/yaml/document.rb +10 -0
  85. data/lib/lutaml/model/yaml/mapping.rb +19 -0
  86. data/lib/lutaml/model/yaml/mapping_rule.rb +9 -0
  87. data/lib/lutaml/model/{yaml_adapter/standard_yaml_adapter.rb → yaml/standard_adapter.rb} +4 -3
  88. data/lib/lutaml/model/yaml/transform.rb +8 -0
  89. data/lib/lutaml/model/yaml.rb +21 -0
  90. data/lib/lutaml/model.rb +40 -4
  91. data/lutaml-model.gemspec +0 -4
  92. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +7 -7
  93. data/spec/fixtures/person.rb +5 -5
  94. data/spec/lutaml/model/attribute_spec.rb +37 -1
  95. data/spec/lutaml/model/cdata_spec.rb +9 -9
  96. data/spec/lutaml/model/collection_spec.rb +50 -2
  97. data/spec/lutaml/model/comparable_model_spec.rb +92 -27
  98. data/spec/lutaml/model/custom_bibtex_adapter_spec.rb +598 -0
  99. data/spec/lutaml/model/custom_vobject_adapter_spec.rb +1226 -0
  100. data/spec/lutaml/model/defaults_spec.rb +1 -1
  101. data/spec/lutaml/model/enum_spec.rb +1 -1
  102. data/spec/lutaml/model/group_spec.rb +333 -20
  103. data/spec/lutaml/model/hash/adapter_spec.rb +255 -0
  104. data/spec/lutaml/model/json_adapter_spec.rb +6 -6
  105. data/spec/lutaml/model/key_value_mapping_spec.rb +65 -3
  106. data/spec/lutaml/model/mixed_content_spec.rb +24 -24
  107. data/spec/lutaml/model/multiple_mapping_spec.rb +5 -5
  108. data/spec/lutaml/model/ordered_content_spec.rb +6 -6
  109. data/spec/lutaml/model/polymorphic_spec.rb +526 -0
  110. data/spec/lutaml/model/render_empty_spec.rb +194 -0
  111. data/spec/lutaml/model/render_nil_spec.rb +206 -22
  112. data/spec/lutaml/model/root_mappings_spec.rb +3 -3
  113. data/spec/lutaml/model/schema/xml_compiler_spec.rb +6 -6
  114. data/spec/lutaml/model/serializable_spec.rb +179 -103
  115. data/spec/lutaml/model/simple_model_spec.rb +9 -9
  116. data/spec/lutaml/model/toml_adapter_spec.rb +6 -6
  117. data/spec/lutaml/model/toml_spec.rb +51 -0
  118. data/spec/lutaml/model/transformation_spec.rb +72 -15
  119. data/spec/lutaml/model/uninitialized_class_spec.rb +96 -0
  120. data/spec/lutaml/model/value_map_spec.rb +240 -0
  121. data/spec/lutaml/model/xml/namespace/nested_with_explicit_namespace_spec.rb +85 -0
  122. data/spec/lutaml/model/xml/namespace_spec.rb +57 -0
  123. data/spec/lutaml/model/xml/xml_element_spec.rb +93 -0
  124. data/spec/lutaml/model/xml_adapter/nokogiri_adapter_spec.rb +2 -2
  125. data/spec/lutaml/model/xml_adapter/oga_adapter_spec.rb +2 -2
  126. data/spec/lutaml/model/xml_adapter/ox_adapter_spec.rb +2 -2
  127. data/spec/lutaml/model/xml_adapter/xml_namespace_spec.rb +6 -6
  128. data/spec/lutaml/model/xml_adapter_spec.rb +6 -6
  129. data/spec/lutaml/model/xml_mapping_rule_spec.rb +105 -5
  130. data/spec/lutaml/model/xml_mapping_spec.rb +70 -16
  131. data/spec/lutaml/model/xml_spec.rb +63 -0
  132. data/spec/lutaml/model/yaml_adapter_spec.rb +3 -5
  133. data/spec/sample_model_spec.rb +3 -3
  134. data/spec/spec_helper.rb +3 -3
  135. metadata +76 -59
  136. data/lib/lutaml/model/json_adapter/json_document.rb +0 -20
  137. data/lib/lutaml/model/json_adapter/json_object.rb +0 -28
  138. data/lib/lutaml/model/loggable.rb +0 -15
  139. data/lib/lutaml/model/mapping_rule.rb +0 -109
  140. data/lib/lutaml/model/toml_adapter/toml_document.rb +0 -20
  141. data/lib/lutaml/model/toml_adapter/toml_object.rb +0 -28
  142. data/lib/lutaml/model/toml_adapter/tomlib_adapter.rb +0 -20
  143. data/lib/lutaml/model/toml_adapter.rb +0 -6
  144. data/lib/lutaml/model/xml_mapping.rb +0 -307
  145. data/lib/lutaml/model/xml_mapping_rule.rb +0 -122
  146. data/lib/lutaml/model/yaml_adapter/yaml_document.rb +0 -20
  147. data/lib/lutaml/model/yaml_adapter/yaml_object.rb +0 -28
  148. data/lib/lutaml/model/yaml_adapter.rb +0 -8
@@ -11,20 +11,34 @@ module Lutaml
11
11
  to:,
12
12
  render_nil: false,
13
13
  render_default: false,
14
+ render_empty: false,
15
+ treat_nil: :nil,
16
+ treat_empty: :empty,
17
+ treat_omitted: :nil,
14
18
  with: {},
15
19
  delegate: nil,
16
20
  child_mappings: nil,
17
21
  root_mappings: nil,
18
- transform: {}
22
+ polymorphic: {},
23
+ polymorphic_map: {},
24
+ transform: {},
25
+ value_map: {}
19
26
  )
20
27
  super(
21
28
  name,
22
29
  to: to,
23
30
  render_nil: render_nil,
24
31
  render_default: render_default,
32
+ render_empty: render_empty,
33
+ treat_nil: treat_nil,
34
+ treat_empty: treat_empty,
35
+ treat_omitted: treat_omitted,
25
36
  with: with,
26
37
  delegate: delegate,
27
- transform: transform
38
+ polymorphic: polymorphic,
39
+ polymorphic_map: polymorphic_map,
40
+ transform: transform,
41
+ value_map: value_map,
28
42
  )
29
43
 
30
44
  @child_mappings = child_mappings
@@ -42,9 +56,11 @@ module Lutaml
42
56
  name.dup,
43
57
  to: to.dup,
44
58
  render_nil: render_nil.dup,
59
+ render_empty: render_empty.dup,
45
60
  with: Utils.deep_dup(custom_methods),
46
61
  delegate: delegate,
47
62
  child_mappings: Utils.deep_dup(child_mappings),
63
+ value_map: Utils.deep_dup(@value_map),
48
64
  )
49
65
  end
50
66
 
@@ -0,0 +1,13 @@
1
+ module Lutaml
2
+ module Model
3
+ class Mapping
4
+ def initialize
5
+ @mappings = []
6
+ end
7
+
8
+ def mappings
9
+ raise NotImplementedError, "#{self.class.name} must implement `mappings`."
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,300 @@
1
+ module Lutaml
2
+ module Model
3
+ class MappingRule
4
+ attr_reader :name,
5
+ :to,
6
+ :render_nil,
7
+ :render_default,
8
+ :render_empty,
9
+ :treat_nil,
10
+ :treat_empty,
11
+ :treat_omitted,
12
+ :attribute,
13
+ :custom_methods,
14
+ :delegate,
15
+ :polymorphic,
16
+ :polymorphic_map,
17
+ :transform,
18
+ :format
19
+
20
+ ALLOWED_OPTIONS = {
21
+ render_nil: %i[
22
+ omit
23
+ as_nil
24
+ as_blank
25
+ as_empty
26
+ ],
27
+ render_empty: %i[
28
+ omit
29
+ as_empty
30
+ as_blank
31
+ as_nil
32
+ ],
33
+ }.freeze
34
+
35
+ ALLOWED_OPTIONS.each do |key, values|
36
+ attribute_name = key.to_s
37
+ values.each do |value|
38
+ define_method(:"#{attribute_name}_#{value}?") do
39
+ send(attribute_name) == value
40
+ end
41
+ end
42
+ end
43
+
44
+ def initialize(
45
+ name,
46
+ to:,
47
+ render_nil: false,
48
+ render_default: false,
49
+ render_empty: false,
50
+ treat_nil: :nil,
51
+ treat_empty: :empty,
52
+ treat_omitted: :nil,
53
+ with: {},
54
+ attribute: false,
55
+ delegate: nil,
56
+ root_mappings: nil,
57
+ polymorphic: {},
58
+ polymorphic_map: {},
59
+ transform: {},
60
+ value_map: {}
61
+ )
62
+ @name = name
63
+ @to = to
64
+ @render_nil = render_nil
65
+ @render_default = render_default
66
+ @render_empty = render_empty
67
+ @treat_nil = treat_nil
68
+ @treat_empty = treat_empty
69
+ @treat_omitted = treat_omitted
70
+ @custom_methods = with
71
+ @attribute = attribute
72
+ @delegate = delegate
73
+ @root_mappings = root_mappings
74
+ @polymorphic = polymorphic
75
+ @polymorphic_map = polymorphic_map
76
+ @transform = transform
77
+
78
+ @value_map = default_value_map
79
+ @value_map[:from].merge!(value_map[:from] || {})
80
+ @value_map[:to].merge!(value_map[:to] || {})
81
+ end
82
+
83
+ def default_value_map(options = {})
84
+ render_nil_as = render_as(:render_nil, :omitted, options)
85
+ render_empty_as = render_as(:render_empty, :empty, options)
86
+
87
+ treat_nil_as = treat_as(:treat_nil, :nil, options)
88
+ treat_empty_as = treat_as(:treat_empty, :empty, options)
89
+ treat_omitted_as = treat_as(:treat_omitted, :nil, options)
90
+
91
+ {
92
+ from: { omitted: treat_omitted_as, nil: treat_nil_as, empty: treat_empty_as },
93
+ to: { omitted: :omitted, nil: render_nil_as, empty: render_empty_as },
94
+ }
95
+ end
96
+
97
+ def render_as(key, default_value, options = {})
98
+ value = public_send(key)
99
+ value = options[key] if value.nil?
100
+
101
+ if value == true
102
+ key.to_s.split("_").last.to_sym
103
+ elsif value == false
104
+ :omitted
105
+ elsif value
106
+ {
107
+ as_empty: :empty,
108
+ as_blank: :empty,
109
+ as_nil: :nil,
110
+ omit: :omitted,
111
+ }[value]
112
+ else
113
+ default_value
114
+ end
115
+ end
116
+
117
+ def treat_as(key, default_value, options = {})
118
+ public_send(key) || options[key] || default_value
119
+ end
120
+
121
+ alias from name
122
+ alias render_default? render_default
123
+ alias attribute? attribute
124
+
125
+ def render?(value, instance = nil, options = {})
126
+ if invalid_value?(value, options)
127
+ false
128
+ elsif instance.respond_to?(:using_default?) && instance.using_default?(to)
129
+ render_default?
130
+ else
131
+ true
132
+ end
133
+ end
134
+
135
+ def treat?(value)
136
+ (treat_nil? || !value.nil?) &&
137
+ (treat_empty? || !Utils.empty?(value)) &&
138
+ (treat_omitted? || Utils.initialized?(value))
139
+ end
140
+
141
+ def render_value_for(value)
142
+ if value.nil?
143
+ value_for_option(value_map(:to)[:nil])
144
+ elsif Utils.empty?(value)
145
+ value_for_option(value_map(:to)[:empty], value)
146
+ elsif Utils.uninitialized?(value)
147
+ value_for_option(value_map(:to)[:omitted])
148
+ else
149
+ value
150
+ end
151
+ end
152
+
153
+ def value_for_option(option, empty_value = nil)
154
+ return nil if option == :nil
155
+ return empty_value || "" if option == :empty
156
+
157
+ Lutaml::Model::UninitializedClass.instance
158
+ end
159
+
160
+ def render_nil?(options = {})
161
+ value_map(:to, options)[:nil] != :omitted
162
+ end
163
+
164
+ def render_empty?(options = {})
165
+ value_map(:to, options)[:empty] != :omitted
166
+ end
167
+
168
+ def render_omitted?(options = {})
169
+ value_map(:to, options)[:omitted] != :omitted
170
+ end
171
+
172
+ def treat_nil?(options = {})
173
+ value_map(:from, options)[:nil] != :omitted
174
+ end
175
+
176
+ def treat_empty?(options = {})
177
+ value_map(:from, options)[:empty] != :omitted
178
+ end
179
+
180
+ def treat_omitted?(options = {})
181
+ value_map(:from, options)[:omitted] != :omitted
182
+ end
183
+
184
+ def polymorphic_mapping?
185
+ polymorphic_map && !polymorphic_map.empty?
186
+ end
187
+
188
+ def serialize_attribute(model, element, doc)
189
+ if custom_methods[:to]
190
+ model.send(custom_methods[:to], model, element, doc)
191
+ end
192
+ end
193
+
194
+ def to_value_for(model)
195
+ if delegate
196
+ model.public_send(delegate).public_send(to)
197
+ else
198
+ return if to.nil?
199
+
200
+ model.public_send(to)
201
+ end
202
+ end
203
+
204
+ def serialize(model, parent = nil, doc = nil)
205
+ if custom_methods[:to]
206
+ model.send(custom_methods[:to], model, parent, doc)
207
+ else
208
+ to_value_for(model)
209
+ end
210
+ end
211
+
212
+ def deserialize(model, value, attributes, mapper_class = nil)
213
+ handle_custom_method(model, value, mapper_class) ||
214
+ handle_delegate(model, value, attributes) ||
215
+ handle_transform_method(model, value, attributes) ||
216
+ assign_value(model, value)
217
+ end
218
+
219
+ def has_custom_method_for_serialization?
220
+ !custom_methods.empty? && custom_methods[:to]
221
+ end
222
+
223
+ def has_custom_method_for_deserialization?
224
+ !custom_methods.empty? && custom_methods[:from]
225
+ end
226
+
227
+ def multiple_mappings?
228
+ name.is_a?(Array)
229
+ end
230
+
231
+ def raw_mapping?
232
+ name == Constants::RAW_MAPPING_KEY
233
+ end
234
+
235
+ def eql?(other)
236
+ other.class == self.class &&
237
+ instance_variables.all? do |var|
238
+ instance_variable_get(var) == other.instance_variable_get(var)
239
+ end
240
+ end
241
+ alias == eql?
242
+
243
+ def deep_dup
244
+ raise NotImplementedError, "Subclasses must implement `deep_dup`."
245
+ end
246
+
247
+ def value_map(key, options = {})
248
+ options = {
249
+ nil: options[:nil],
250
+ empty: options[:empty],
251
+ omitted: options[:omitted],
252
+ }.compact
253
+
254
+ @value_map[key].merge(options)
255
+ end
256
+
257
+ private
258
+
259
+ # if value is nil and render nil is false, will not render
260
+ # if value is empty and render empty is false, will not render
261
+ # if value is uninitialized and render omitted is false, will not render
262
+ def invalid_value?(value, options)
263
+ (!render_nil?(options) && value.nil?) ||
264
+ (!render_empty?(options) && Utils.empty?(value)) ||
265
+ (!render_omitted?(options) && Utils.uninitialized?(value))
266
+ end
267
+
268
+ def handle_custom_method(model, value, mapper_class)
269
+ return if !custom_methods[:from] || value.nil?
270
+
271
+ mapper_class.new.send(custom_methods[:from], model, value)
272
+ true
273
+ end
274
+
275
+ def handle_delegate(model, value, attributes)
276
+ return unless delegate
277
+
278
+ handle_nil_or_uninitialized(model, attributes)
279
+ assign_value(model.public_send(delegate), value)
280
+ true
281
+ end
282
+
283
+ def handle_nil_or_uninitialized(model, attributes)
284
+ delegate_value = model.public_send(delegate)
285
+ return if Utils.initialized?(delegate_value) && !delegate_value.nil?
286
+
287
+ model.public_send(:"#{delegate}=", attributes[delegate].type.new)
288
+ end
289
+
290
+ def handle_transform_method(model, value, attributes)
291
+ assign_value(model, ImportTransformer.call(value, self, attributes[to]))
292
+ true
293
+ end
294
+
295
+ def assign_value(model, value)
296
+ model.public_send(:"#{to}=", value)
297
+ end
298
+ end
299
+ end
300
+ end
@@ -19,7 +19,7 @@ module Lutaml
19
19
  require "lutaml/model"
20
20
  <%=
21
21
  requiring_files = resolve_required_files(content)
22
- if requiring_files.any?
22
+ if requiring_files&.any?
23
23
  requiring_files.map { |file| "require_relative \\\"\#{file}\\\"" }.join("\n") + "\n"
24
24
  end
25
25
  -%>
@@ -168,8 +168,8 @@ module Lutaml
168
168
  return if schemas.empty?
169
169
 
170
170
  schemas.each do |schema|
171
- schema_to_models(schema.include) if schema.include.any?
172
- schema_to_models(schema.import) if schema.import.any?
171
+ schema_to_models(schema.include) if schema.include&.any?
172
+ schema_to_models(schema.import) if schema.import&.any?
173
173
  resolved_element_order(schema).each do |order_item|
174
174
  item_name = order_item&.name
175
175
  case order_item
@@ -205,7 +205,7 @@ module Lutaml
205
205
  hash[:min_length] = restriction.min_length.map(&:value).max if restriction.min_length&.any?
206
206
  hash[:min_inclusive] = restriction.min_inclusive.map(&:value).max if restriction.min_inclusive&.any?
207
207
  hash[:max_inclusive] = restriction.max_inclusive.map(&:value).min if restriction.max_inclusive&.any?
208
- hash[:length] = restriction_length(restriction.length) if restriction.length.any?
208
+ hash[:length] = restriction_length(restriction.length) if restriction.length&.any?
209
209
  end
210
210
 
211
211
  def restriction_length(lengths)
@@ -219,8 +219,8 @@ module Lutaml
219
219
 
220
220
  def setup_complex_type(complex_type)
221
221
  MappingHash.new.tap do |hash|
222
- hash[:attributes] = [] if complex_type.attribute.any?
223
- hash[:attribute_groups] = [] if complex_type.attribute_group.any?
222
+ hash[:attributes] = [] if complex_type.attribute&.any?
223
+ hash[:attribute_groups] = [] if complex_type.attribute_group&.any?
224
224
  hash[:mixed] = complex_type.mixed
225
225
  resolved_element_order(complex_type).each do |element|
226
226
  case element
@@ -253,10 +253,10 @@ module Lutaml
253
253
 
254
254
  def setup_sequence(sequence)
255
255
  MappingHash.new.tap do |hash|
256
- hash[:sequences] = [] if sequence.sequence.any?
257
- hash[:elements] = [] if sequence.element.any?
258
- hash[:choice] = [] if sequence.choice.any?
259
- hash[:groups] = [] if sequence.group.any?
256
+ hash[:sequences] = [] if sequence.sequence&.any?
257
+ hash[:elements] = [] if sequence.element&.any?
258
+ hash[:choice] = [] if sequence.choice&.any?
259
+ hash[:groups] = [] if sequence.group&.any?
260
260
  resolved_element_order(sequence).each do |instance|
261
261
  case instance
262
262
  when Xsd::Sequence
@@ -340,8 +340,8 @@ module Lutaml
340
340
  if attribute_group.ref
341
341
  hash[:ref_class] = attribute_group.ref
342
342
  else
343
- hash[:attributes] = [] if attribute_group.attribute.any?
344
- hash[:attribute_groups] = [] if attribute_group.attribute_group.any?
343
+ hash[:attributes] = [] if attribute_group.attribute&.any?
344
+ hash[:attribute_groups] = [] if attribute_group.attribute_group&.any?
345
345
  resolved_element_order(attribute_group).each do |instance|
346
346
  case instance
347
347
  when Xsd::Attribute
@@ -380,14 +380,14 @@ module Lutaml
380
380
  hash[:base_class] = restriction.base
381
381
  restriction_patterns(restriction.pattern, hash) if restriction.respond_to?(:pattern)
382
382
  restriction_content(hash, restriction)
383
- return hash unless restriction.respond_to?(:enumeration) && restriction.enumeration.any?
383
+ return hash unless restriction.respond_to?(:enumeration) && restriction.enumeration&.any?
384
384
 
385
385
  hash[:values] = restriction.enumeration.map(&:value)
386
386
  hash
387
387
  end
388
388
 
389
389
  def restriction_patterns(patterns, hash)
390
- return if patterns.empty?
390
+ return if Utils.blank?(patterns)
391
391
 
392
392
  hash[:pattern] = patterns.map { |p| "(#{p.value})" }.join("|")
393
393
  hash
@@ -426,7 +426,7 @@ module Lutaml
426
426
  MappingHash.new.tap do |hash|
427
427
  hash[:min_occurs] = element.min_occurs if element.min_occurs
428
428
  hash[:max_occurs] = element.max_occurs if element.max_occurs
429
- element_hash[:arguments] = hash if hash.any?
429
+ element_hash[:arguments] = hash if hash&.any?
430
430
  end
431
431
  end
432
432
 
@@ -1,8 +1,8 @@
1
1
  module Lutaml
2
2
  module Model
3
3
  class Sequence
4
- attr_reader :attributes,
5
- :model
4
+ attr_accessor :model
5
+ attr_reader :attributes
6
6
 
7
7
  def initialize(model)
8
8
  @attributes = []
@@ -0,0 +1,22 @@
1
+ module Lutaml
2
+ module Model
3
+ class SerializationAdapter
4
+ def self.handles_format(format)
5
+ # Lutaml::Model::Config.register_format(format, self)
6
+ @handles = format
7
+ end
8
+
9
+ def self.document_class(klass = nil)
10
+ if klass
11
+ @document_class = klass
12
+ else
13
+ @document_class
14
+ end
15
+ end
16
+
17
+ def self.parse(data, _options = {})
18
+ document_class.parse(data, create_additions: false)
19
+ end
20
+ end
21
+ end
22
+ end