lutaml 0.9.26 → 0.9.28

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 63135b601a74ae7525807e9b57974a2db686e49f6e6992918e7d209bdbf27460
4
- data.tar.gz: 529878c2d79c6f35130ef8c34eb5223d16c46a10f96cf470e43c8563457491a8
3
+ metadata.gz: c3d4343125b51531e1c2cab816a8a9e85ada1764ecaef15c1598038124167ba6
4
+ data.tar.gz: 0bb4810dfe1e8d1cc363379d5f5cfbee8e778bf2ccb6dda67bcaf2360d625034
5
5
  SHA512:
6
- metadata.gz: e70e2318f24f4a6c6beccdd8c6db99f8674ab92b7763a398ffc3b2617b6a44b2ef2b431fa039d5cabe58719d7660c96f2bde96c3dc8ecfc9fd904de7ac025cc9
7
- data.tar.gz: 61f20ab2448dfaf836a698b1596ec0685f3d90380bcf2829e08ebda2f7b39dffddb9b0913609ccb682df77a66d2ada3f69e90071556a422a973eda5784942732
6
+ metadata.gz: af85cb2b8f1e4ae8ab8e2fb7831c4ef995b39899150ed35debada9e22f5211032ad1249bd1e45a35bb13708c1355d5a2d2a13df5821bd6ed5cc16e1bccbb8c8e
7
+ data.tar.gz: '019cd5694d0a1a91ec72116680728bb848ba184693af97f096d2d929ffda1b64fdf2d0bc0ba71d2e1b3fec0d060e1e2aeab122ab9683ee85bbc582b6d0000233'
data/README.adoc CHANGED
@@ -31,52 +31,53 @@ $ gem install lutaml
31
31
  === Parsing
32
32
 
33
33
  The `Lutaml::Parser.parse` method provides a single point of entry for parsing
34
- data model files.
34
+ data model files, such as:
35
35
 
36
- The return object is always a `Lutaml::LutamlPath::DocumentWrapper` object,
37
- where `#original_document` returns the native parsed models.
36
+ * EXPRESS files with `.exp` extension
37
+ * YAML Compressed EXPRESS CACHE files
38
+ * XMI files with `.xmi` extension
39
+ * XML files with `.xml` extension
40
+ * LutaML files with `.lutaml` extension
41
+ * LutaML YAML files with `.yml` extension
42
+
43
+ Depending on the input file type, `Lutaml::Parser.parse` returns:
44
+
45
+ * `Expressir::Express::Model::Repository` for EXPRESS files
46
+ * `Expressir::Express::Cache` for EXPRESS CACHE files
47
+ * `Lutaml::Uml::Document` for XMI files
48
+ * `Lutaml::Uml::Document` for XML files
49
+ * `Lutaml::Uml::Document` for LutaML files
50
+ * `Lutaml::Uml::Document` for LutaML YAML files
51
+
52
+ Examples to use the `Lutaml::Parser.parse`:
38
53
 
39
54
  [source,ruby]
40
55
  ----
56
+ require "lutaml"
57
+
41
58
  # example.exp is an EXPRESS schema file
42
- wrapper = Lutaml::Parser.parse([File.new("example.exp")])
43
- # => returns a Lutaml::LutamlPath::DocumentWrapper object
44
- wrapper.original_document
45
- # => returns the original Expressir::Repository object
46
- ----
59
+ model = Lutaml::Parser.parse([File.new("example.exp")])
60
+ # => returns Expressir::Express::Model::Repository model
47
61
 
48
- [source,ruby]
49
- ----
50
62
  # example.exp.yaml is an EXPRESS cache file created with Expressir
51
- wrapper = Lutaml::Parser.parse([File.new("example.exp.yaml")], ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
52
- # => returns the DocumentWrapper but with the repository loaded from the Expressir cache file
53
- ----
54
-
63
+ model = Lutaml::Parser.parse([File.new("example.exp.yaml")], ::Lutaml::Parser::EXPRESS_CACHE_PARSE_TYPE)
64
+ # => returns Expressir::Express::Cache model
55
65
 
56
- === Selecting EXPRESS schemas
66
+ # example.xmi is an XMI file
67
+ model = Lutaml::Parser.parse([File.new("example.xmi")])
68
+ # => returns Lutaml::Uml::Document model
57
69
 
58
- LutaML supports the `ModelElement#to_hash(..., select_proc:)` functionality
59
- of Expressir, allowing Expressir to only call `to_hash` on schemas that
60
- fit a dynamic criteria.
70
+ # example.xml is an XML file
71
+ model = Lutaml::Parser.parse([File.new("example.xml")])
72
+ # => returns Lutaml::Uml::Document model
61
73
 
62
- The criteria is set via a Ruby `Proc` object, as follows.
74
+ # example.lutaml is an LutaML file
75
+ model = Lutaml::Parser.parse([File.new("example.lutaml")])
76
+ # => returns Lutaml::Uml::Document model
63
77
 
64
- [source,ruby]
65
- ----
66
- # Sets the filter
67
- filtered_schemas = ["action_schema", "date_time_schema"]
68
-
69
- # Sets the Proc
70
- wrapper.select_proc = Proc.new do |value|
71
- if value.is_a?(Expressir::Model::Declarations::Schema)
72
- filtered_schemas.include?(value.id)
73
- else
74
- true
75
- end
76
- end
77
-
78
- serialized = wrapper.to_liquid
79
- # => returns the filtered to_hash method
78
+ # example.yaml is an LutaML YAML file
79
+ model = Lutaml::Parser.parse([File.new("example.yaml")])
80
+ # => returns Lutaml::Uml::Document model
80
81
  ----
81
82
 
82
83
 
data/lib/lutaml/parser.rb CHANGED
@@ -2,8 +2,6 @@ require "lutaml/express"
2
2
  require "lutaml/uml"
3
3
  require "lutaml/xmi"
4
4
  require "lutaml/xml"
5
- require "lutaml/uml/lutaml_path/document_wrapper"
6
- require "lutaml/express/lutaml_path/document_wrapper"
7
5
  require "expressir/express/cache"
8
6
 
9
7
  module Lutaml
@@ -14,14 +12,10 @@ module Lutaml
14
12
 
15
13
  class << self
16
14
  def parse(file_list, input_type = nil)
17
- file_list = file_list.is_a?(Array) ? file_list : [file_list]
18
- new(Array(file_list), input_type).parse
19
- end
20
-
21
- def parse_into_document(file_list, input_type = nil)
22
- file_list = file_list.is_a?(Array) ? file_list : [file_list]
15
+ file_list = [file_list] unless file_list.is_a?(Array)
23
16
  new(Array(file_list), input_type).parse_into_document
24
17
  end
18
+ alias_method :parse_into_document, :parse
25
19
  end
26
20
 
27
21
  def initialize(file_list, input_type)
@@ -29,15 +23,7 @@ module Lutaml
29
23
  @file_list = file_list
30
24
  end
31
25
 
32
- def parse
33
- documents = parse_into_document
34
- return document_wrapper(documents) if ["exp",
35
- EXPRESS_CACHE_PARSE_TYPE].include?(parse_type)
36
-
37
- documents.map { |doc| document_wrapper(doc) }
38
- end
39
-
40
- def parse_into_document
26
+ def parse_into_document # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
41
27
  case parse_type
42
28
  when "exp"
43
29
  Expressir::Express::Parser.from_files(file_list.map(&:path))
@@ -55,19 +41,5 @@ module Lutaml
55
41
  raise ArgumentError, "Unsupported file format"
56
42
  end
57
43
  end
58
-
59
- private
60
-
61
- def document_wrapper(document)
62
- if ["exp", EXPRESS_CACHE_PARSE_TYPE].include?(parse_type)
63
- return Lutaml::Express::LutamlPath::DocumentWrapper.new(document)
64
- end
65
-
66
- if parse_type == "xml"
67
- return Lutaml::Xml::LutamlPath::DocumentWrapper.new(document)
68
- end
69
-
70
- Lutaml::Uml::LutamlPath::DocumentWrapper.new(document)
71
- end
72
44
  end
73
45
  end
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.26".freeze
2
+ VERSION = "0.9.28".freeze
3
3
  end
@@ -48,19 +48,19 @@ module Lutaml
48
48
  private
49
49
 
50
50
  # @param xml [String]
51
- # @return [Shale::Mapper]
51
+ # @return [Lutaml::Model::Serializable]
52
52
  def get_xmi_model(xml)
53
53
  Xmi::Sparx::SparxRoot.parse_xml(File.read(xml))
54
54
  end
55
55
  end
56
56
 
57
- # @param xmi_model [Shale::Mapper]
57
+ # @param xmi_model [Lutaml::Model::Serializable]
58
58
  def set_xmi_model(xmi_model)
59
59
  @xmi_cache = {}
60
60
  @xmi_root_model = xmi_model
61
61
  end
62
62
 
63
- # @param xmi_model [Shale::Mapper]
63
+ # @param xmi_model [Lutaml::Model::Serializable]
64
64
  # @return [Lutaml::Uml::Document]
65
65
  def parse(xmi_model)
66
66
  set_xmi_model(xmi_model)
@@ -69,7 +69,7 @@ module Lutaml
69
69
  ::Lutaml::Uml::Document.new(serialized_hash)
70
70
  end
71
71
 
72
- # @param xmi_model [Shale::Mapper]
72
+ # @param xmi_model [Lutaml::Model::Serializable]
73
73
  # @param with_gen: [Boolean]
74
74
  # @param with_absolute_path: [Boolean]
75
75
  # return [Hash]
@@ -82,7 +82,7 @@ module Lutaml
82
82
  )
83
83
  end
84
84
 
85
- # @param xmi_model [Shale::Mapper]
85
+ # @param xmi_model [Lutaml::Model::Serializable]
86
86
  # @param guidance_yaml [String]
87
87
  # return [Liquid::Drop]
88
88
  def serialize_xmi_to_liquid(xmi_model, guidance_yaml = nil)
@@ -104,7 +104,7 @@ module Lutaml
104
104
  YAML.safe_load(File.read(yaml, encoding: "UTF-8"))
105
105
  end
106
106
 
107
- # @param xmi_model [Shale::Mapper]
107
+ # @param xmi_model [Lutaml::Model::Serializable]
108
108
  # @param name [String]
109
109
  # @param guidance_yaml [String]
110
110
  # @return [Hash]
@@ -120,7 +120,7 @@ module Lutaml
120
120
 
121
121
  private
122
122
 
123
- # @param xmi_model [Shale::Mapper]
123
+ # @param xmi_model [Lutaml::Model::Serializable]
124
124
  # @param with_gen: [Boolean]
125
125
  # @param with_absolute_path: [Boolean]
126
126
  # @return [Hash]
@@ -138,7 +138,7 @@ module Lutaml
138
138
  }
139
139
  end
140
140
 
141
- # @param model [Shale::Mapper]
141
+ # @param model [Lutaml::Model::Serializable]
142
142
  # @param with_gen: [Boolean]
143
143
  # @param with_absolute_path: [Boolean]
144
144
  # @param absolute_path: [String]
@@ -188,7 +188,7 @@ module Lutaml
188
188
  end
189
189
  end
190
190
 
191
- # @param package [Shale::Mapper]
191
+ # @param package [Lutaml::Model::Serializable]
192
192
  # @return [String]
193
193
  def get_package_name(package) # rubocop:disable Metrics/AbcSize
194
194
  return package.name unless package.name.nil?
@@ -202,8 +202,8 @@ module Lutaml
202
202
  "unnamed"
203
203
  end
204
204
 
205
- # @param package [Shale::Mapper]
206
- # @param model [Shale::Mapper]
205
+ # @param package [Lutaml::Model::Serializable]
206
+ # @param model [Lutaml::Model::Serializable]
207
207
  # @param with_gen: [Boolean]
208
208
  # @param with_absolute_path: [Boolean]
209
209
  # @return [Array<Hash>]
@@ -228,8 +228,8 @@ module Lutaml
228
228
  end
229
229
  end
230
230
 
231
- # @param klass [Shale::Mapper]
232
- # @param model [Shale::Mapper]
231
+ # @param klass [Lutaml::Model::Serializable]
232
+ # @param model [Lutaml::Model::Serializable]
233
233
  # @param with_gen: [Boolean]
234
234
  # @param with_absolute_path: [Boolean]
235
235
  # @return [Hash]
@@ -258,7 +258,7 @@ module Lutaml
258
258
  klass_hash
259
259
  end
260
260
 
261
- # @param klass [Shale::Mapper]
261
+ # @param klass [Lutaml::Model::Serializable]
262
262
  # # @return [Hash]
263
263
  def serialize_generalization(klass)
264
264
  general_hash, next_general_node_id = get_top_level_general_hash(klass)
@@ -271,7 +271,7 @@ module Lutaml
271
271
  general_hash
272
272
  end
273
273
 
274
- # @param klass [Shale::Mapper]
274
+ # @param klass [Lutaml::Model::Serializable]
275
275
  # @return [Array<Hash>]
276
276
  def get_top_level_general_hash(klass) # rubocop:disable Metrics/AbcSize
277
277
  general_hash, next_general_node_id = get_general_hash(klass.id)
@@ -305,7 +305,7 @@ module Lutaml
305
305
  end
306
306
 
307
307
  # @param xmi_id [String]
308
- # @param model [Shale::Mapper]
308
+ # @param model [Lutaml::Model::Serializable]
309
309
  # @return [Array<Hash>]
310
310
  # @note get generalization node and its owned attributes
311
311
  def serialize_generalization_attributes(general_id)
@@ -321,18 +321,18 @@ module Lutaml
321
321
  end
322
322
 
323
323
  # @param xmi_id [String]
324
- # @return [Shale::Mapper]
324
+ # @return [Lutaml::Model::Serializable]
325
325
  def get_general_node(xmi_id)
326
326
  find_packaged_element_by_id(xmi_id)
327
327
  end
328
328
 
329
- # @param general_node [Shale::Mapper]
329
+ # @param general_node [Lutaml::Model::Serializable]
330
330
  # @return [Hash]
331
331
  def get_general_attributes(general_node)
332
332
  serialize_class_attributes(general_node, with_assoc: true)
333
333
  end
334
334
 
335
- # @param general_node [Shale::Mapper]
335
+ # @param general_node [Lutaml::Model::Serializable]
336
336
  # @return [String]
337
337
  def get_next_general_node_id(general_node)
338
338
  general_node.generalization.first&.general
@@ -361,13 +361,13 @@ module Lutaml
361
361
  end
362
362
 
363
363
  # @param id [String]
364
- # @return [Shale::Mapper]
364
+ # @return [Lutaml::Model::Serializable]
365
365
  def find_packaged_element_by_id(id)
366
366
  all_packaged_elements.find { |e| e.id == id }
367
367
  end
368
368
 
369
369
  # @param id [String]
370
- # @return [Shale::Mapper]
370
+ # @return [Lutaml::Model::Serializable]
371
371
  def find_upper_level_packaged_element(klass_id)
372
372
  upper_klass = all_packaged_elements.find do |e|
373
373
  e.packaged_element.find { |pe| pe.id == klass_id }
@@ -376,7 +376,7 @@ module Lutaml
376
376
  end
377
377
 
378
378
  # @param path [String]
379
- # @return [Shale::Mapper]
379
+ # @return [Lutaml::Model::Serializable]
380
380
  def find_klass_packaged_element(path)
381
381
  lutaml_path = Lutaml::Path.parse(path)
382
382
  if lutaml_path.segments.count == 1
@@ -387,7 +387,7 @@ module Lutaml
387
387
  end
388
388
 
389
389
  # @param path [Lutaml::Path::ElementPath]
390
- # @return [Shale::Mapper]
390
+ # @return [Lutaml::Model::Serializable]
391
391
  def find_klass_packaged_element_by_path(path)
392
392
  if path.absolute?
393
393
  iterate_packaged_element(
@@ -399,7 +399,7 @@ module Lutaml
399
399
  end
400
400
 
401
401
  # @param name_array [Array<String>]
402
- # @return [Shale::Mapper]
402
+ # @return [Lutaml::Model::Serializable]
403
403
  def iterate_relative_packaged_element(name_array)
404
404
  # match the first element in the name_array
405
405
  matched_elements = all_packaged_elements.select do |e|
@@ -414,11 +414,11 @@ module Lutaml
414
414
  result.compact.first
415
415
  end
416
416
 
417
- # @param model [Shale::Mapper]
417
+ # @param model [Lutaml::Model::Serializable]
418
418
  # @param name_array [Array<String>]
419
419
  # @param index: [Integer]
420
420
  # @param type: [String]
421
- # @return [Shale::Mapper]
421
+ # @return [Lutaml::Model::Serializable]
422
422
  def iterate_packaged_element(model, name_array,
423
423
  index: 1, type: "uml:Package")
424
424
  return model if index == name_array.count
@@ -435,7 +435,7 @@ module Lutaml
435
435
  end
436
436
 
437
437
  # @param name [String]
438
- # @return [Shale::Mapper]
438
+ # @return [Lutaml::Model::Serializable]
439
439
  def find_klass_packaged_element_by_name(name)
440
440
  all_packaged_elements.find do |e|
441
441
  e.type?("uml:Class") && e.name == name
@@ -443,14 +443,14 @@ module Lutaml
443
443
  end
444
444
 
445
445
  # @param name [String]
446
- # @return [Shale::Mapper]
446
+ # @return [Lutaml::Model::Serializable]
447
447
  def find_packaged_element_by_name(name)
448
448
  all_packaged_elements.find do |e|
449
449
  e.name == name
450
450
  end
451
451
  end
452
452
 
453
- # @param package [Shale::Mapper]
453
+ # @param package [Lutaml::Model::Serializable]
454
454
  # @return [Array<Hash>]
455
455
  # @note xpath ./packagedElement[@xmi:type="uml:Enumeration"]
456
456
  def serialize_model_enums(package)
@@ -466,7 +466,7 @@ module Lutaml
466
466
  end
467
467
  end
468
468
 
469
- # @param model [Shale::Mapper]
469
+ # @param model [Lutaml::Model::Serializable]
470
470
  # @return [Hash]
471
471
  # @note xpath .//ownedLiteral[@xmi:type="uml:EnumerationLiteral"]
472
472
  def serialize_enum_owned_literal(enum)
@@ -486,7 +486,7 @@ module Lutaml
486
486
  end
487
487
  end
488
488
 
489
- # @param model [Shale::Mapper]
489
+ # @param model [Lutaml::Model::Serializable]
490
490
  # @return [Array<Hash>]
491
491
  # @note xpath ./packagedElement[@xmi:type="uml:DataType"]
492
492
  def serialize_model_data_types(model)
@@ -576,7 +576,7 @@ module Lutaml
576
576
  end
577
577
 
578
578
  # @param link_id [String]
579
- # @return [Shale::Mapper]
579
+ # @return [Lutaml::Model::Serializable]
580
580
  # @note xpath %(//connector[@xmi:idref="#{link_id}"])
581
581
  def fetch_connector(link_id)
582
582
  @xmi_root_model.extension.connectors.connector.find do |con|
@@ -594,7 +594,7 @@ module Lutaml
594
594
  connector_node.send(node_name.to_sym).documentation
595
595
  end
596
596
 
597
- # @param klass [Shale::Mapper]
597
+ # @param klass [Lutaml::Model::Serializable]
598
598
  # @return [Array<Hash>]
599
599
  # @note xpath .//ownedOperation
600
600
  def serialize_class_operations(klass)
@@ -638,7 +638,7 @@ module Lutaml
638
638
  end
639
639
 
640
640
  # @param owner_xmi_id [String]
641
- # @param link [Shale::Mapper]
641
+ # @param link [Lutaml::Model::Serializable]
642
642
  # @param link_member_name [String]
643
643
  # @return [String]
644
644
  def serialize_owned_type(owner_xmi_id, link, linke_owner_name)
@@ -665,7 +665,7 @@ module Lutaml
665
665
  end
666
666
 
667
667
  # @param owner_xmi_id [String]
668
- # @param link [Shale::Mapper]
668
+ # @param link [Lutaml::Model::Serializable]
669
669
  # @return [Array<String, String>]
670
670
  def serialize_member_end(owner_xmi_id, link)
671
671
  case link.name
@@ -706,7 +706,7 @@ module Lutaml
706
706
  end
707
707
 
708
708
  # @param owner_xmi_id [String]
709
- # @param link [Shale::Mapper]
709
+ # @param link [Lutaml::Model::Serializable]
710
710
  # @param link_member_name [String]
711
711
  # @return [Array<String, String, Hash, String, String>]
712
712
  def serialize_member_type(owner_xmi_id, link, link_member_name)
@@ -750,7 +750,7 @@ module Lutaml
750
750
  end
751
751
 
752
752
  # @param owner_xmi_id [String]
753
- # @param link [Shale::Mapper]
753
+ # @param link [Lutaml::Model::Serializable]
754
754
  # @return [Array<String, String, Hash, String, String>]
755
755
  # @note match return value of serialize_member_type
756
756
  def generalization_association(owner_xmi_id, link)
@@ -796,7 +796,7 @@ module Lutaml
796
796
  end
797
797
 
798
798
  # @param klass_id [String]
799
- # @return [Shale::Mapper]
799
+ # @return [Lutaml::Model::Serializable]
800
800
  # @note xpath %(//element[@xmi:idref="#{klass['xmi:id']}"])
801
801
  def fetch_element(klass_id)
802
802
  @xmi_root_model.extension.elements.element.find do |e|
@@ -804,7 +804,7 @@ module Lutaml
804
804
  end
805
805
  end
806
806
 
807
- # @param klass [Shale::Mapper]
807
+ # @param klass [Lutaml::Model::Serializable]
808
808
  # @param with_assoc [Boolean]
809
809
  # @return [Array<Hash>]
810
810
  # @note xpath .//ownedAttribute[@xmi:type="uml:Property"]
@@ -920,7 +920,7 @@ module Lutaml
920
920
  }
921
921
  end
922
922
 
923
- # @node [Shale::Mapper]
923
+ # @node [Lutaml::Model::Serializable]
924
924
  # @attr_name [String]
925
925
  # @return [String]
926
926
  # @note xpath %(//element[@xmi:idref="#{xmi_id}"]/properties)
@@ -928,11 +928,13 @@ module Lutaml
928
928
  doc_node = fetch_element(node_id)
929
929
  return unless doc_node
930
930
 
931
- doc_node.properties&.send(Shale::Utils.snake_case(attr_name).to_sym)
931
+ doc_node.properties&.send(
932
+ Lutaml::Model::Utils.snake_case(attr_name).to_sym,
933
+ )
932
934
  end
933
935
 
934
936
  # @param xmi_id [String]
935
- # @return [Shale::Mapper]
937
+ # @return [Lutaml::Model::Serializable]
936
938
  # @note xpath %(//attribute[@xmi:idref="#{xmi_id}"])
937
939
  def fetch_attribute_node(xmi_id)
938
940
  attribute_node = nil
@@ -1045,15 +1047,15 @@ module Lutaml
1045
1047
  all_elements
1046
1048
  end
1047
1049
 
1048
- # @param items [Array<Shale::Mapper>]
1049
- # @param model [Shale::Mapper]
1050
+ # @param items [Array<Lutaml::Model::Serializable>]
1051
+ # @param model [Lutaml::Model::Serializable]
1050
1052
  # @param type [String] nil for any
1051
1053
  def select_all_items(items, model, type, method)
1052
1054
  iterate_tree(items, model, type, method.to_sym)
1053
1055
  end
1054
1056
 
1055
- # @param all_elements [Array<Shale::Mapper>]
1056
- # @param model [Shale::Mapper]
1057
+ # @param all_elements [Array<Lutaml::Model::Serializable>]
1058
+ # @param model [Lutaml::Model::Serializable]
1057
1059
  # @param type [String] nil for any
1058
1060
  # @note xpath ./packagedElement[@xmi:type="#{type}"]
1059
1061
  def select_all_packaged_elements(all_elements, model, type)
@@ -1063,8 +1065,8 @@ module Lutaml
1063
1065
  end
1064
1066
  end
1065
1067
 
1066
- # @param result [Array<Shale::Mapper>]
1067
- # @param node [Shale::Mapper]
1068
+ # @param result [Array<Lutaml::Model::Serializable>]
1069
+ # @param node [Lutaml::Model::Serializable]
1068
1070
  # @param type [String] nil for any
1069
1071
  # @param children_method [String] method to determine children exist
1070
1072
  def iterate_tree(result, node, type, children_method)
@@ -1081,7 +1083,7 @@ module Lutaml
1081
1083
  end
1082
1084
 
1083
1085
  # @param result [Hash]
1084
- # @param node [Shale::Mapper]
1086
+ # @param node [Lutaml::Model::Serializable]
1085
1087
  # @note set id as key and name as value into result
1086
1088
  # if id and name are found
1087
1089
  def map_id_name(result, node)
@@ -2,8 +2,9 @@ require "nokogiri"
2
2
  require "htmlentities"
3
3
  require "lutaml/uml/has_attributes"
4
4
  require "lutaml/uml/document"
5
-
6
- require "shale/schema"
5
+ require "lutaml/xsd"
6
+ require "lutaml/model"
7
+ require "lutaml/model/schema"
7
8
 
8
9
  module Lutaml
9
10
  module Xml
@@ -11,12 +12,10 @@ module Lutaml
11
12
  # Class for parsing .xml schema files into ::Lutaml::Uml::Document
12
13
  class Xml
13
14
  def self.load_schema(schema, root_schema)
14
- result = Shale::Schema.from_xml([schema])
15
+ result = Lutaml::Model::Schema.from_xml(schema)
15
16
 
16
17
  result.values.each do |klass|
17
- # Temporary solution will update in the parser
18
18
  klass = klass.gsub(/^require.*?\n/, "")
19
- klass = klass.gsub(/< Shale::Mapper/, "< Lutaml::Xml::Mapper")
20
19
 
21
20
  eval(klass, TOPLEVEL_BINDING)
22
21
  end
@@ -39,18 +38,6 @@ module Lutaml
39
38
 
40
39
  @root_class.from_xml(doc)
41
40
  end
42
-
43
- private
44
-
45
- def load_schema(schema)
46
- result = Shale::Schema.from_xml([schema])
47
-
48
- result.values.each do |klass|
49
- klass = klass.gsub(/^require.*?\n/, "")
50
-
51
- eval(klass, TOPLEVEL_BINDING)
52
- end
53
- end
54
41
  end
55
42
  end
56
43
  end
data/lib/lutaml/xml.rb CHANGED
@@ -1,9 +1 @@
1
1
  require "lutaml/xml/parsers/xml"
2
-
3
- require "lutaml/xml/mapper"
4
- require "lutaml/xml/lutaml_path/document_wrapper"
5
-
6
- require "shale"
7
- require "shale/adapter/nokogiri"
8
-
9
- Shale.xml_adapter = Shale::Adapter::Nokogiri
data/lutaml.gemspec CHANGED
@@ -33,12 +33,14 @@ Gem::Specification.new do |spec|
33
33
  spec.add_dependency "hashie", "~> 4.1.0"
34
34
  spec.add_dependency "htmlentities"
35
35
  spec.add_dependency "liquid"
36
+ spec.add_dependency "lutaml-model"
36
37
  spec.add_dependency "lutaml-path"
38
+ spec.add_dependency "lutaml-xsd"
37
39
  spec.add_dependency "nokogiri", "~> 1.10"
38
40
  spec.add_dependency "parslet", "~> 2.0.0"
39
41
  spec.add_dependency "ruby-graphviz", "~> 1.2"
40
42
  spec.add_dependency "thor", "~> 1.0"
41
- spec.add_dependency "xmi", "~> 0.3.10"
43
+ spec.add_dependency "xmi", "~> 0.3.12"
42
44
 
43
45
  spec.add_development_dependency "byebug"
44
46
  spec.add_development_dependency "equivalent-xml", "~> 0.6.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lutaml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.26
4
+ version: 0.9.28
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-01-10 00:00:00.000000000 Z
11
+ date: 2025-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: lutaml-model
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: lutaml-path
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: lutaml-xsd
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: nokogiri
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -142,14 +170,14 @@ dependencies:
142
170
  requirements:
143
171
  - - "~>"
144
172
  - !ruby/object:Gem::Version
145
- version: 0.3.10
173
+ version: 0.3.12
146
174
  type: :runtime
147
175
  prerelease: false
148
176
  version_requirements: !ruby/object:Gem::Requirement
149
177
  requirements:
150
178
  - - "~>"
151
179
  - !ruby/object:Gem::Version
152
- version: 0.3.10
180
+ version: 0.3.12
153
181
  - !ruby/object:Gem::Dependency
154
182
  name: byebug
155
183
  requirement: !ruby/object:Gem::Requirement
@@ -284,8 +312,6 @@ files:
284
312
  - lib/lutaml/command_line.rb
285
313
  - lib/lutaml/express.rb
286
314
  - lib/lutaml/express/README.adoc
287
- - lib/lutaml/express/lutaml_path/document_wrapper.rb
288
- - lib/lutaml/express/lutaml_path/formatter.rb
289
315
  - lib/lutaml/express/parsers/exp.rb
290
316
  - lib/lutaml/express/version.rb
291
317
  - lib/lutaml/formatter.rb
@@ -293,7 +319,6 @@ files:
293
319
  - lib/lutaml/formatter/graphviz.rb
294
320
  - lib/lutaml/layout/engine.rb
295
321
  - lib/lutaml/layout/graph_viz_engine.rb
296
- - lib/lutaml/lutaml_path/document_wrapper.rb
297
322
  - lib/lutaml/parser.rb
298
323
  - lib/lutaml/sysml.rb
299
324
  - lib/lutaml/sysml/README.md
@@ -339,7 +364,6 @@ files:
339
364
  - lib/lutaml/uml/has_attributes.rb
340
365
  - lib/lutaml/uml/has_members.rb
341
366
  - lib/lutaml/uml/instance.rb
342
- - lib/lutaml/uml/lutaml_path/document_wrapper.rb
343
367
  - lib/lutaml/uml/model.rb
344
368
  - lib/lutaml/uml/node/base.rb
345
369
  - lib/lutaml/uml/node/class_node.rb
@@ -399,8 +423,6 @@ files:
399
423
  - lib/lutaml/xmi/parsers/xml.rb
400
424
  - lib/lutaml/xmi/version.rb
401
425
  - lib/lutaml/xml.rb
402
- - lib/lutaml/xml/lutaml_path/document_wrapper.rb
403
- - lib/lutaml/xml/mapper.rb
404
426
  - lib/lutaml/xml/parsers/xml.rb
405
427
  - lutaml.gemspec
406
428
  homepage: https://github.com/lutaml/lutaml
@@ -1,22 +0,0 @@
1
- require "lutaml/lutaml_path/document_wrapper"
2
- require "lutaml/express/lutaml_path/formatter"
3
-
4
- module Lutaml
5
- module Express
6
- module LutamlPath
7
- class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
8
- attr_accessor :select_proc
9
-
10
- protected
11
-
12
- def serialize_document(repository)
13
- repository.to_hash(
14
- formatter: Formatter,
15
- include_empty: true,
16
- select_proc: select_proc,
17
- )
18
- end
19
- end
20
- end
21
- end
22
- end
@@ -1,14 +0,0 @@
1
- require "expressir/express/formatter"
2
- require "expressir/express/schema_head_formatter"
3
- require "expressir/express/hyperlink_formatter"
4
-
5
- module Lutaml
6
- module Express
7
- module LutamlPath
8
- class Formatter < Expressir::Express::Formatter
9
- include Expressir::Express::SchemaHeadFormatter
10
- include Expressir::Express::HyperlinkFormatter
11
- end
12
- end
13
- end
14
- end
@@ -1,51 +0,0 @@
1
- module Lutaml
2
- module LutamlPath
3
- class DocumentWrapper
4
- attr_reader :serialized_document, :original_document
5
-
6
- def initialize(document)
7
- @original_document = document
8
- end
9
-
10
- def to_liquid
11
- serialized_document
12
- end
13
-
14
- def serialized_document
15
- @serialized_document ||= serialize_document(@original_document)
16
- end
17
-
18
- protected
19
-
20
- def serialize_document(_path)
21
- raise ArgumentError, "implement #serialize_document!"
22
- end
23
-
24
- def serialize_value(attr_value)
25
- if attr_value.is_a?(Array)
26
- return attr_value.map(&method(:serialize_to_hash))
27
- end
28
-
29
- serialize_to_hash(attr_value)
30
- end
31
-
32
- BASE_OBJECTS = [String, Integer, Float, FalseClass, TrueClass, Symbol, NilClass, Hash]
33
- def serialize_to_hash(object)
34
- return object if BASE_OBJECTS.include?(object.class)
35
-
36
- object.instance_variables.each_with_object({}) do |var, res|
37
- variable = object.instance_variable_get(var)
38
- res[var.to_s.gsub("@", "")] = if variable.is_a?(Array)
39
- variable.map do |n|
40
- serialize_to_hash(n)
41
- end
42
- elsif BASE_OBJECTS.include?(variable.class) || var == :@parent
43
- variable
44
- else
45
- serialize_to_hash(variable)
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end
@@ -1,15 +0,0 @@
1
- require "lutaml/lutaml_path/document_wrapper"
2
-
3
- module Lutaml
4
- module Uml
5
- module LutamlPath
6
- class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
7
- protected
8
-
9
- def serialize_document(document)
10
- serialize_to_hash(document)
11
- end
12
- end
13
- end
14
- end
15
- end
@@ -1,45 +0,0 @@
1
- require "lutaml/lutaml_path/document_wrapper"
2
-
3
- module Lutaml
4
- module Xml
5
- module LutamlPath
6
- class DocumentWrapper < ::Lutaml::LutamlPath::DocumentWrapper
7
- protected
8
-
9
- def serialize_document(document)
10
- serialize_to_hash(document)
11
- end
12
-
13
- def serialize_to_hash(object)
14
- hash = {}
15
- attribute_name = nil
16
-
17
- object.all_content.each do |mapping, content|
18
- if mapping == "content"
19
- attribute_name = object.class.xml_mapping.content.attribute.to_s
20
- hash[attribute_name] ||= []
21
- hash[attribute_name] << content.strip unless content.strip&.empty?
22
- elsif content.is_a?(String)
23
- if object.class.attributes[mapping.attribute].collection?
24
- hash[mapping.name] ||= []
25
- hash[mapping.name] << content.strip
26
- else
27
- hash[mapping.name] = content.strip
28
- end
29
- else
30
- if object.class.attributes[mapping.attribute].collection?
31
- hash[mapping.name] ||= []
32
- hash[mapping.name] << serialize_to_hash(content)
33
- else
34
- hash[mapping.name] = serialize_to_hash(content)
35
- end
36
- end
37
- end
38
-
39
- hash[attribute_name] = hash[attribute_name].compact if attribute_name
40
- hash
41
- end
42
- end
43
- end
44
- end
45
- end
@@ -1,448 +0,0 @@
1
- require "shale"
2
-
3
- module Lutaml
4
- module Xml
5
- class Mapper < Shale::Mapper
6
- # rubocop:disable Metrics/AbcSize
7
- # rubocop:disable Metrics/MethodLength
8
- # rubocop:disable Metrics/BlockLength
9
- # rubocop:disable Metrics/CyclomaticComplexity
10
- # rubocop:disable Metrics/PerceivedComplexity
11
- class << self
12
- # Convert XML document to Object
13
- #
14
- # @param [Shale::Adapter::<XML adapter>::Node] element
15
- # @param [Array<Symbol>] only
16
- # @param [Array<Symbol>] except
17
- # @param [any] context
18
- #
19
- # @return [model instance]
20
- #
21
- # @api public
22
- def of_xml(element, only: nil, except: nil, context: nil)
23
- instance = model.new
24
-
25
- attributes
26
- .values
27
- .select(&:default)
28
- .each { |attr| instance.send(attr.setter, attr.default.call) }
29
-
30
- grouping = Shale::Mapping::Group::XmlGrouping.new
31
- delegates = Shale::Mapping::Delegates.new
32
-
33
- only = to_partial_render_attributes(only)
34
- except = to_partial_render_attributes(except)
35
-
36
- element.attributes.each do |key, value|
37
- mapping = xml_mapping.attributes[key.to_s]
38
- next unless mapping
39
-
40
- if mapping.group
41
- grouping.add(mapping, :attribute, value)
42
- elsif mapping.method_from
43
- mapper = new
44
-
45
- if mapper.method(mapping.method_from).arity == 3
46
- mapper.send(mapping.method_from, instance, value, context)
47
- else
48
- mapper.send(mapping.method_from, instance, value)
49
- end
50
- else
51
- receiver_attributes = get_receiver_attributes(mapping)
52
- attribute = receiver_attributes[mapping.attribute]
53
- next unless attribute
54
-
55
- next if only && !only.key?(attribute.name)
56
- next if except&.key?(attribute.name)
57
-
58
- casted_value = attribute.type.cast(value)
59
-
60
- if attribute.collection?
61
- if mapping.receiver
62
- delegates.add_collection(
63
- attributes[mapping.receiver],
64
- attribute.setter,
65
- casted_value,
66
- )
67
- else
68
- instance.send(attribute.name) << casted_value
69
- end
70
- elsif mapping.receiver
71
- delegates.add(attributes[mapping.receiver], attribute.setter,
72
- casted_value)
73
- else
74
- instance.send(attribute.setter, casted_value)
75
- end
76
- end
77
- end
78
-
79
- content_mapping = xml_mapping.content
80
-
81
- if content_mapping
82
- if content_mapping.group
83
- grouping.add(content_mapping, :content, element)
84
- elsif content_mapping.method_from
85
- mapper = new
86
-
87
- if mapper.method(content_mapping.method_from).arity == 3
88
- mapper.send(content_mapping.method_from, instance, element,
89
- context)
90
- else
91
- mapper.send(content_mapping.method_from, instance, element)
92
- end
93
- else
94
- get_content_value(content_mapping, element, only, except,
95
- delegates, instance)
96
- end
97
- end
98
-
99
- # rubocop:disable Metrics/BlockNesting
100
- element.instance_variable_get(:@node)&.children&.each do |nokogiri_node|
101
- if nokogiri_node.name == "text"
102
- content_value = get_content_value(content_mapping, nokogiri_node,
103
- only, except, delegates, instance)
104
- instance.all_content << ["content", content_value]
105
- next
106
- elsif nokogiri_node.name == "comment"
107
- instance.all_content << ["comment", nokogiri_node.text]
108
- next
109
- end
110
-
111
- node = element.class.new(nokogiri_node)
112
- mapping = xml_mapping.elements[node.name]
113
-
114
- next unless mapping
115
-
116
- if mapping.group
117
- grouping.add(mapping, :element, node)
118
- elsif mapping.method_from
119
- mapper = new
120
-
121
- if mapper.method(mapping.method_from).arity == 3
122
- mapper.send(mapping.method_from, instance, node, context)
123
- else
124
- mapper.send(mapping.method_from, instance, node)
125
- end
126
- else
127
- receiver_attributes = get_receiver_attributes(mapping)
128
- attribute = receiver_attributes[mapping.attribute]
129
- next unless attribute
130
-
131
- if only
132
- attribute_only = only[attribute.name]
133
- next unless only.key?(attribute.name)
134
- end
135
-
136
- if except
137
- attribute_except = except[attribute.name]
138
- next if except.key?(attribute.name) && attribute_except.nil?
139
- end
140
-
141
- value = attribute.type.of_xml(
142
- node,
143
- only: attribute_only,
144
- except: attribute_except,
145
- context: context,
146
- )
147
-
148
- casted_value = attribute.type.cast(value)
149
- instance.all_content << [mapping, casted_value]
150
-
151
- if attribute.collection?
152
- if mapping.receiver
153
- delegates.add_collection(
154
- attributes[mapping.receiver],
155
- attribute.setter,
156
- casted_value,
157
- )
158
- else
159
- instance.send(attribute.name) << casted_value
160
- end
161
- elsif mapping.receiver
162
- delegates.add(attributes[mapping.receiver], attribute.setter,
163
- casted_value)
164
- else
165
- instance.send(attribute.setter, casted_value)
166
- end
167
- end
168
- end
169
- # rubocop:enable Metrics/BlockNesting
170
-
171
- delegates.each do |delegate|
172
- receiver = get_receiver(instance, delegate.receiver_attribute)
173
- receiver.send(delegate.setter, delegate.value)
174
- end
175
-
176
- grouping.each do |group|
177
- mapper = new
178
-
179
- if mapper.method(group.method_from).arity == 3
180
- mapper.send(group.method_from, instance, group.dict, context)
181
- else
182
- mapper.send(group.method_from, instance, group.dict)
183
- end
184
- end
185
-
186
- instance
187
- end
188
-
189
- # Convert Object to XML document
190
- #
191
- # @param [any] instance Object to convert
192
- # @param [String, nil] node_name XML node name
193
- # @param [Shale::Adapter::<xml adapter>::Document, nil]
194
- # doc Object to convert
195
- # @param [Array<Symbol>] only
196
- # @param [Array<Symbol>] except
197
- # @param [any] context
198
- #
199
- # @raise [IncorrectModelError]
200
- #
201
- # @return [::REXML::Document, ::Nokogiri::Document, ::Ox::Document]
202
- #
203
- # @api public
204
- def as_xml(
205
- instance,
206
- node_name = nil,
207
- doc = nil,
208
- _cdata = nil,
209
- only: nil,
210
- except: nil,
211
- context: nil,
212
- version: nil
213
- )
214
- unless instance.is_a?(model)
215
- msg = "argument is a '#{instance.class}' but should be a '#{model}'"
216
- raise IncorrectModelError, msg
217
- end
218
-
219
- unless doc
220
- doc = Shale.xml_adapter.create_document(version)
221
-
222
- element = as_xml(
223
- instance,
224
- xml_mapping.prefixed_root,
225
- doc,
226
- only: only,
227
- except: except,
228
- context: context,
229
- )
230
- doc.add_element(doc.doc, element)
231
-
232
- return doc.doc
233
- end
234
-
235
- element = doc.create_element(node_name)
236
-
237
- doc.add_namespace(
238
- xml_mapping.default_namespace.prefix,
239
- xml_mapping.default_namespace.name,
240
- )
241
-
242
- grouping = Shale::Mapping::Group::XmlGrouping.new
243
-
244
- only = to_partial_render_attributes(only)
245
- except = to_partial_render_attributes(except)
246
-
247
- # rubocop:disable Metrics/BlockNesting
248
- xml_mapping.attributes.each_value do |mapping|
249
- if mapping.group
250
- grouping.add(mapping, :attribute, nil)
251
- elsif mapping.method_to
252
- mapper = new
253
-
254
- if mapper.method(mapping.method_to).arity == 4
255
- mapper.send(mapping.method_to, instance, element, doc, context)
256
- else
257
- mapper.send(mapping.method_to, instance, element, doc)
258
- end
259
- else
260
- receiver = if mapping.receiver
261
- instance.send(mapping.receiver)
262
- else
263
- instance
264
- end
265
-
266
- receiver_attributes = get_receiver_attributes(mapping)
267
- attribute = receiver_attributes[mapping.attribute]
268
- next unless attribute
269
-
270
- next if only && !only.key?(attribute.name)
271
- next if except&.key?(attribute.name)
272
-
273
- value = receiver.send(attribute.name) if receiver
274
-
275
- if mapping.render_nil? || !value.nil?
276
- doc.add_namespace(mapping.namespace.prefix,
277
- mapping.namespace.name)
278
- doc.add_attribute(element, mapping.prefixed_name, value)
279
- end
280
- end
281
- end
282
- # rubocop:enable Metrics/BlockNesting
283
-
284
- # rubocop:disable Metrics/BlockNesting
285
- instance.all_content.each do |mapping, content|
286
- if mapping == "comment"
287
- comment = Nokogiri::XML::Comment.new(doc.doc, content)
288
- doc.add_element(element, comment)
289
- elsif mapping == "content"
290
- content_mapping = xml_mapping.content
291
- if content_mapping
292
- if content_mapping.group
293
- grouping.add(content_mapping, :content, nil)
294
- elsif content_mapping.method_to
295
- mapper = new
296
-
297
- if mapper.method(content_mapping.method_to).arity == 4
298
- mapper.send(content_mapping.method_to, instance, element,
299
- doc, context)
300
- else
301
- mapper.send(content_mapping.method_to, instance, element, doc)
302
- end
303
- else
304
- receiver_attributes = get_receiver_attributes(content_mapping)
305
- attribute = receiver_attributes[content_mapping.attribute]
306
-
307
- if attribute
308
- skip = false
309
-
310
- skip = true if only && !only.key?(attribute.name)
311
- skip = true if except&.key?(attribute.name)
312
-
313
- unless skip
314
- # value = receiver.send(attribute.name) if receiver
315
- value = content
316
-
317
- if content_mapping.cdata
318
- doc.create_cdata(value, element)
319
- else
320
- a = Nokogiri::XML::Text.new(value, doc.doc)
321
- doc.add_element(element, a)
322
- end
323
- end
324
- end
325
- end
326
- end
327
- elsif mapping.group
328
- grouping.add(mapping, :element, nil)
329
- elsif mapping.method_to
330
- mapper = new
331
-
332
- if mapper.method(mapping.method_to).arity == 4
333
- mapper.send(mapping.method_to, instance, element, doc, context)
334
- else
335
- mapper.send(mapping.method_to, instance, element, doc)
336
- end
337
- else
338
- receiver_attributes = get_receiver_attributes(mapping)
339
- attribute = receiver_attributes[mapping.attribute]
340
- next unless attribute
341
-
342
- if only
343
- attribute_only = only[attribute.name]
344
- next unless only.key?(attribute.name)
345
- end
346
-
347
- if except
348
- attribute_except = except[attribute.name]
349
- next if except.key?(attribute.name) && attribute_except.nil?
350
- end
351
-
352
- value = content
353
-
354
- if mapping.render_nil? || !value.nil?
355
- doc.add_namespace(mapping.namespace.prefix,
356
- mapping.namespace.name)
357
- end
358
-
359
- if value.nil?
360
- if mapping.render_nil?
361
- child = doc.create_element(mapping.prefixed_name)
362
- doc.add_element(element, child)
363
- end
364
- elsif attribute.collection?
365
- [*value].each do |v|
366
- next if v.nil?
367
-
368
- child = attribute.type.as_xml(
369
- v,
370
- mapping.prefixed_name,
371
- doc,
372
- mapping.cdata,
373
- only: attribute_only,
374
- except: attribute_except,
375
- context: context,
376
- )
377
- doc.add_element(element, child)
378
- end
379
- else
380
- child = attribute.type.as_xml(
381
- value,
382
- mapping.prefixed_name,
383
- doc,
384
- mapping.cdata,
385
- only: attribute_only,
386
- except: attribute_except,
387
- context: context,
388
- )
389
- doc.add_element(element, child)
390
- end
391
- end
392
- end
393
- # rubocop:enable Metrics/BlockNesting
394
-
395
- grouping.each do |group|
396
- mapper = new
397
-
398
- if mapper.method(group.method_to).arity == 4
399
- mapper.send(group.method_to, instance, element, doc, context)
400
- else
401
- mapper.send(group.method_to, instance, element, doc)
402
- end
403
- end
404
-
405
- element
406
- end
407
-
408
- def get_content_value(content_mapping, element, only, except, delegates, instance)
409
- receiver_attributes = get_receiver_attributes(content_mapping)
410
- attribute = receiver_attributes[content_mapping.attribute]
411
-
412
- if attribute
413
- skip = false
414
-
415
- # rubocop:disable Metrics/BlockNesting
416
- skip = true if only && !only.key?(attribute.name)
417
- skip = true if except&.key?(attribute.name)
418
-
419
- unless skip
420
- value = attribute.type.cast(attribute.type.of_xml(element))
421
-
422
- if content_mapping.receiver
423
- delegates.add(attributes[content_mapping.receiver],
424
- attribute.setter, value)
425
- else
426
- instance.send(attribute.setter, value)
427
- end
428
- end
429
- # rubocop:enable Metrics/BlockNesting
430
- end
431
- end
432
- end
433
- # rubocop:enable Metrics/AbcSize
434
- # rubocop:enable Metrics/MethodLength
435
- # rubocop:enable Metrics/BlockLength
436
- # rubocop:enable Metrics/CyclomaticComplexity
437
- # rubocop:enable Metrics/PerceivedComplexity
438
-
439
- attr_accessor :all_content
440
-
441
- def initialize(*args)
442
- @all_content = []
443
-
444
- super
445
- end
446
- end
447
- end
448
- end