lutaml-model 0.6.7 → 0.7.1

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 (60) 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_todo.yml +18 -33
  5. data/README.adoc +4380 -2557
  6. data/lib/lutaml/model/attribute.rb +94 -15
  7. data/lib/lutaml/model/choice.rb +7 -0
  8. data/lib/lutaml/model/comparable_model.rb +48 -9
  9. data/lib/lutaml/model/error/collection_count_out_of_range_error.rb +1 -1
  10. data/lib/lutaml/model/error/polymorphic_error.rb +9 -0
  11. data/lib/lutaml/model/error.rb +1 -0
  12. data/lib/lutaml/model/mapping/json_mapping.rb +17 -0
  13. data/lib/lutaml/model/{key_value_mapping.rb → mapping/key_value_mapping.rb} +58 -14
  14. data/lib/lutaml/model/{key_value_mapping_rule.rb → mapping/key_value_mapping_rule.rb} +18 -2
  15. data/lib/lutaml/model/mapping/mapping_rule.rb +299 -0
  16. data/lib/lutaml/model/mapping/toml_mapping.rb +25 -0
  17. data/lib/lutaml/model/{xml_mapping.rb → mapping/xml_mapping.rb} +97 -15
  18. data/lib/lutaml/model/{xml_mapping_rule.rb → mapping/xml_mapping_rule.rb} +20 -3
  19. data/lib/lutaml/model/mapping/yaml_mapping.rb +17 -0
  20. data/lib/lutaml/model/mapping.rb +14 -0
  21. data/lib/lutaml/model/schema/xml_compiler.rb +15 -15
  22. data/lib/lutaml/model/sequence.rb +2 -2
  23. data/lib/lutaml/model/serialize.rb +247 -97
  24. data/lib/lutaml/model/type/date.rb +1 -1
  25. data/lib/lutaml/model/type/date_time.rb +2 -2
  26. data/lib/lutaml/model/type/hash.rb +1 -1
  27. data/lib/lutaml/model/type/time.rb +2 -2
  28. data/lib/lutaml/model/type/time_without_date.rb +2 -2
  29. data/lib/lutaml/model/uninitialized_class.rb +64 -0
  30. data/lib/lutaml/model/utils.rb +14 -0
  31. data/lib/lutaml/model/validation.rb +1 -0
  32. data/lib/lutaml/model/version.rb +1 -1
  33. data/lib/lutaml/model/xml_adapter/nokogiri_adapter.rb +1 -1
  34. data/lib/lutaml/model/xml_adapter/oga_adapter.rb +1 -1
  35. data/lib/lutaml/model/xml_adapter/ox_adapter.rb +1 -1
  36. data/lib/lutaml/model/xml_adapter/xml_document.rb +38 -17
  37. data/lib/lutaml/model/xml_adapter/xml_element.rb +17 -7
  38. data/lib/lutaml/model.rb +1 -0
  39. data/spec/benchmarks/xml_parsing_benchmark_spec.rb +3 -3
  40. data/spec/fixtures/person.rb +5 -5
  41. data/spec/lutaml/model/attribute_spec.rb +37 -1
  42. data/spec/lutaml/model/cdata_spec.rb +2 -2
  43. data/spec/lutaml/model/collection_spec.rb +50 -2
  44. data/spec/lutaml/model/comparable_model_spec.rb +92 -27
  45. data/spec/lutaml/model/defaults_spec.rb +1 -1
  46. data/spec/lutaml/model/enum_spec.rb +1 -1
  47. data/spec/lutaml/model/group_spec.rb +316 -14
  48. data/spec/lutaml/model/key_value_mapping_spec.rb +41 -3
  49. data/spec/lutaml/model/polymorphic_spec.rb +348 -0
  50. data/spec/lutaml/model/render_empty_spec.rb +194 -0
  51. data/spec/lutaml/model/render_nil_spec.rb +206 -22
  52. data/spec/lutaml/model/simple_model_spec.rb +9 -9
  53. data/spec/lutaml/model/value_map_spec.rb +240 -0
  54. data/spec/lutaml/model/xml/namespace/nested_with_explicit_namespace_spec.rb +85 -0
  55. data/spec/lutaml/model/xml/xml_element_spec.rb +93 -0
  56. data/spec/lutaml/model/xml_mapping_rule_spec.rb +102 -2
  57. data/spec/lutaml/model/xml_mapping_spec.rb +45 -3
  58. data/spec/sample_model_spec.rb +3 -3
  59. metadata +20 -8
  60. data/lib/lutaml/model/mapping_rule.rb +0 -109
@@ -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 = []