lutaml 0.9.32 → 0.9.34

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 (55) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -0
  3. data/bin/plantuml2lutaml +1 -1
  4. data/bin/yaml2lutaml +6 -4
  5. data/exe/lutaml-wsd2uml +1 -1
  6. data/exe/lutaml-yaml2uml +6 -4
  7. data/lib/lutaml/command_line.rb +3 -3
  8. data/lib/lutaml/formatter/base.rb +3 -3
  9. data/lib/lutaml/formatter/graphviz.rb +10 -10
  10. data/lib/lutaml/sysml/block.rb +1 -1
  11. data/lib/lutaml/sysml/constraint_block.rb +1 -1
  12. data/lib/lutaml/sysml/nested_connector_end.rb +1 -1
  13. data/lib/lutaml/sysml/requirement.rb +41 -33
  14. data/lib/lutaml/sysml/xmi_file.rb +382 -355
  15. data/lib/lutaml/uml/actor.rb +1 -1
  16. data/lib/lutaml/uml/association.rb +5 -5
  17. data/lib/lutaml/uml/connector.rb +1 -1
  18. data/lib/lutaml/uml/constructor_end.rb +1 -1
  19. data/lib/lutaml/uml/dependency.rb +1 -1
  20. data/lib/lutaml/uml/document.rb +0 -1
  21. data/lib/lutaml/uml/formatter/base.rb +2 -2
  22. data/lib/lutaml/uml/formatter/graphviz.rb +10 -10
  23. data/lib/lutaml/uml/has_members.rb +4 -4
  24. data/lib/lutaml/uml/instance.rb +1 -1
  25. data/lib/lutaml/uml/model.rb +1 -1
  26. data/lib/lutaml/uml/node/class_node.rb +1 -1
  27. data/lib/lutaml/uml/operation.rb +2 -2
  28. data/lib/lutaml/uml/package.rb +2 -2
  29. data/lib/lutaml/uml/parsers/dsl.rb +7 -4
  30. data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +6 -3
  31. data/lib/lutaml/uml/property.rb +4 -4
  32. data/lib/lutaml/uml/top_element.rb +2 -2
  33. data/lib/lutaml/uml/top_element_attribute.rb +1 -1
  34. data/lib/lutaml/uml/value.rb +2 -2
  35. data/lib/lutaml/version.rb +1 -1
  36. data/lib/lutaml/xmi/liquid_drops/association_drop.rb +11 -2
  37. data/lib/lutaml/xmi/liquid_drops/attribute_drop.rb +2 -2
  38. data/lib/lutaml/xmi/liquid_drops/connector_drop.rb +40 -0
  39. data/lib/lutaml/xmi/liquid_drops/data_type_drop.rb +3 -2
  40. data/lib/lutaml/xmi/liquid_drops/diagram_drop.rb +1 -1
  41. data/lib/lutaml/xmi/liquid_drops/enum_drop.rb +1 -1
  42. data/lib/lutaml/xmi/liquid_drops/enum_owned_literal_drop.rb +1 -1
  43. data/lib/lutaml/xmi/liquid_drops/generalization_attribute_drop.rb +1 -1
  44. data/lib/lutaml/xmi/liquid_drops/generalization_drop.rb +1 -1
  45. data/lib/lutaml/xmi/liquid_drops/klass_drop.rb +3 -2
  46. data/lib/lutaml/xmi/liquid_drops/operation_drop.rb +1 -1
  47. data/lib/lutaml/xmi/liquid_drops/package_drop.rb +1 -1
  48. data/lib/lutaml/xmi/liquid_drops/root_drop.rb +1 -1
  49. data/lib/lutaml/xmi/liquid_drops/source_target_drop.rb +36 -0
  50. data/lib/lutaml/xmi/parsers/xmi_base.rb +41 -19
  51. data/lib/lutaml/xmi/parsers/xml.rb +24 -29
  52. data/lib/lutaml/xmi.rb +0 -1
  53. data/lutaml.gemspec +2 -10
  54. metadata +6 -103
  55. data/lib/lutaml/xmi/version.rb +0 -5
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lutaml
4
+ module XMI
5
+ class SourceTargetDrop < Liquid::Drop
6
+ include Parsers::XMIBase
7
+
8
+ def initialize(model, options = {}) # rubocop:disable Lint/MissingSuper
9
+ @model = model
10
+ @options = options
11
+ @xmi_root_model = options[:xmi_root_model]
12
+ @id_name_mapping = options[:id_name_mapping]
13
+ end
14
+
15
+ def idref
16
+ @model.idref
17
+ end
18
+
19
+ def name
20
+ @model&.role&.name
21
+ end
22
+
23
+ def type
24
+ @model&.model&.name
25
+ end
26
+
27
+ def documentation
28
+ @model&.documentation&.value
29
+ end
30
+
31
+ def multiplicity
32
+ @model&.type&.multiplicity
33
+ end
34
+ end
35
+ end
36
+ end
@@ -4,7 +4,7 @@ require "lutaml/uml/has_attributes"
4
4
  require "lutaml/uml/document"
5
5
  require "lutaml/xmi"
6
6
  require "xmi"
7
- require 'digest'
7
+ require "digest"
8
8
 
9
9
  module Lutaml
10
10
  module XMI
@@ -25,10 +25,15 @@ module Lutaml
25
25
  end
26
26
 
27
27
  # @param xmi_model [Lutaml::Model::Serializable]
28
- def set_xmi_model(xmi_model, xmi_cache = nil)
29
- @xmi_cache = xmi_cache ? xmi_cache : {}
30
- @xmi_root_model = xmi_model
31
- map_id_name(@xmi_cache, @xmi_root_model) if @xmi_cache.empty?
28
+ # @param id_name_mapping [Hash]
29
+ # @return [Hash]
30
+ def set_xmi_model(xmi_model, id_name_mapping = nil)
31
+ @id_name_mapping ||= id_name_mapping || {}
32
+ @xmi_root_model ||= xmi_model
33
+
34
+ if @id_name_mapping.empty?
35
+ map_id_name(@id_name_mapping, @xmi_root_model)
36
+ end
32
37
  end
33
38
 
34
39
  private
@@ -107,7 +112,7 @@ module Lutaml
107
112
  return package.name unless package.name.nil?
108
113
 
109
114
  connector = fetch_connector(package.id)
110
- if connector.target&.model && connector.target.model&.name
115
+ if connector.target&.model&.name
111
116
  return "#{connector.target.model.name} " \
112
117
  "(#{package.type.split(':').last})"
113
118
  end
@@ -307,7 +312,7 @@ module Lutaml
307
312
  # @return [Lutaml::Model::Serializable]
308
313
  def find_klass_packaged_element(path)
309
314
  lutaml_path = Lutaml::Path.parse(path)
310
- if lutaml_path.segments.count == 1
315
+ if lutaml_path.segments.one?
311
316
  return find_klass_packaged_element_by_name(path)
312
317
  end
313
318
 
@@ -519,7 +524,13 @@ module Lutaml
519
524
  # %(//connector[@xmi:idref="#{link_id}"]/#{node_name}/documentation)
520
525
  def fetch_definition_node_value(link_id, node_name)
521
526
  connector_node = fetch_connector(link_id)
522
- connector_node.send(node_name.to_sym).documentation
527
+ documentation = connector_node.send(node_name.to_sym).documentation
528
+
529
+ if documentation.is_a?(Xmi::Sparx::SparxElementDocumentation)
530
+ documentation&.value
531
+ else
532
+ documentation
533
+ end
523
534
  end
524
535
 
525
536
  # @param klass [Lutaml::Model::Serializable]
@@ -637,7 +648,7 @@ module Lutaml
637
648
  # @param link [Lutaml::Model::Serializable]
638
649
  # @param link_member_name [String]
639
650
  # @return [Array<String, String, Hash, String, String>]
640
- def serialize_member_type(owner_xmi_id, link, link_member_name)
651
+ def serialize_member_type(owner_xmi_id, link, link_member_name) # rubocop:disable Metrics/MethodLength
641
652
  member_end, xmi_id = serialize_member_end(owner_xmi_id, link)
642
653
 
643
654
  if link.name == "Association"
@@ -649,16 +660,26 @@ module Lutaml
649
660
  fetch_owned_attribute_node(xmi_id)
650
661
  end
651
662
 
663
+ if fetch_connector_name(link.id)
664
+ member_end = fetch_connector_name(link.id)
665
+ end
666
+
652
667
  [member_end, "aggregation", member_end_cardinality,
653
668
  member_end_attribute_name, xmi_id]
654
669
  end
655
670
 
671
+ def fetch_connector_name(link_id)
672
+ connector = fetch_connector(link_id)
673
+ connector&.name
674
+ end
675
+
656
676
  # @param link_id [String]
657
677
  # @param connector_type [String]
658
678
  # @return [Array<Hash, String>]
659
679
  # @note xpath %(//connector[@xmi:idref="#{link_id}"]/#{connector_type})
660
- def fetch_assoc_connector(link_id, connector_type) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
661
- assoc_connector = fetch_connector(link_id).send(connector_type.to_sym)
680
+ def fetch_assoc_connector(link_id, connector_type) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
681
+ connector = fetch_connector(link_id)
682
+ assoc_connector = connector.send(connector_type.to_sym)
662
683
 
663
684
  if assoc_connector
664
685
  assoc_connector_type = assoc_connector.type
@@ -667,9 +688,8 @@ module Lutaml
667
688
  cardinality.unshift("1") if cardinality.length == 1
668
689
  min, max = cardinality
669
690
  end
691
+
670
692
  assoc_connector_role = assoc_connector.role
671
- # Does role has name attribute? Or get name from model?
672
- # attribute_name = assoc_connector_role.name if assoc_connector_role
673
693
  attribute_name = assoc_connector.model.name if assoc_connector_role
674
694
  cardinality = cardinality_min_max_value(min, max)
675
695
  end
@@ -875,7 +895,7 @@ module Lutaml
875
895
  next unless e.attributes&.attribute
876
896
 
877
897
  e.attributes.attribute.each do |a|
878
- cache[a.idref] = a # Store in hash for quick lookup
898
+ cache[a.idref] = a # Store in hash for quick lookup
879
899
  end
880
900
  end
881
901
  cache
@@ -907,8 +927,8 @@ module Lutaml
907
927
  # @param xmi_id [String]
908
928
  # @return [String]
909
929
  def lookup_entity_name(xmi_id)
910
- model_node_name_by_xmi_id(xmi_id) if @xmi_cache.empty?
911
- @xmi_cache[xmi_id]
930
+ model_node_name_by_xmi_id(xmi_id) if @id_name_mapping.empty?
931
+ @id_name_mapping[xmi_id]
912
932
  end
913
933
 
914
934
  # @param xmi_id [String]
@@ -923,8 +943,10 @@ module Lutaml
923
943
  # @param xmi_id [String]
924
944
  # @param source_or_target [String]
925
945
  # @return [String]
926
- def connector_name_by_source_or_target(xmi_id, source_or_target)
946
+ def connector_name_by_source_or_target(xmi_id, source_or_target) # rubocop:disable Metrics/AbcSize
927
947
  node = connector_node_by_id(xmi_id, source_or_target)
948
+ return node.name if node&.name
949
+
928
950
  return if node.nil? ||
929
951
  node.send(source_or_target.to_sym).nil? ||
930
952
  node.send(source_or_target.to_sym).model.nil?
@@ -962,8 +984,8 @@ module Lutaml
962
984
  def model_node_name_by_xmi_id(xmi_id)
963
985
  id_name_mapping = Hash.new
964
986
  map_id_name(id_name_mapping, @xmi_root_model)
965
- @xmi_cache = id_name_mapping
966
- @xmi_cache[xmi_id]
987
+ @id_name_mapping = id_name_mapping
988
+ @id_name_mapping[xmi_id]
967
989
  end
968
990
 
969
991
  # @return [Array<Xmi::Uml::PackagedElement>]
@@ -11,10 +11,11 @@ module Lutaml
11
11
  module Parsers
12
12
  # Class for parsing .xmi schema files into ::Lutaml::Uml::Document
13
13
  class XML
14
- @xmi_cache_static = {}
14
+ @id_name_mapping_static = {}
15
15
  @xmi_root_model_cache_static = {}
16
16
 
17
- attr_reader :xmi_cache, :xmi_root_model, :all_packaged_elements_cache
17
+ attr_reader :id_name_mapping, :xmi_root_model,
18
+ :all_packaged_elements_cache
18
19
 
19
20
  include XMIBase
20
21
 
@@ -42,38 +43,30 @@ module Lutaml
42
43
  new.serialize_xmi_to_liquid(xmi_model, guidance)
43
44
  end
44
45
 
45
- # @param xml [String] path to xml
46
+ # @param xmi_path [String] path to xml
46
47
  # @param name [String]
47
48
  # @param guidance [String]
48
49
  # @return [Hash]
49
- def serialize_generalization_by_name(xml, name, guidance = nil)
50
- # puts "#{xml}, #{name}, #{guidance}"
51
-
50
+ def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength
51
+ xmi_path, name, guidance = nil
52
+ )
52
53
  # Load from cache or file
53
- xml_cache_key = (Digest::SHA256.file xml).hexdigest
54
- xmi_model = deep_clone(@xmi_root_model_cache_static[xml_cache_key])
55
- xmi_model_to_cache = nil
56
- if xmi_model == nil
57
- xmi_model = get_xmi_model(xml)
58
- xmi_model_to_cache = deep_clone(xmi_model)
59
- end
60
- xmi_cache = @xmi_cache_static[xml_cache_key]
54
+ xml_cache_key = (Digest::SHA256.file xmi_path).hexdigest
55
+ xmi_model = @xmi_root_model_cache_static[xml_cache_key] ||
56
+ get_xmi_model(xmi_path)
57
+ id_name_mapping = @id_name_mapping_static[xml_cache_key]
61
58
 
62
59
  instance = new
63
- ret_val = instance.serialize_generalization_by_name(xmi_model, name, guidance, xmi_cache)
60
+ ret_val = instance.serialize_generalization_by_name(
61
+ xmi_model, name, guidance, id_name_mapping
62
+ )
64
63
 
65
- # Put to cache
66
- @xmi_cache_static[xml_cache_key] = instance.xmi_cache if guidance == nil
67
- @xmi_root_model_cache_static[xml_cache_key] = xmi_model_to_cache if xmi_model_to_cache
64
+ # Put xmi_model and id_name_mapping to cache
65
+ @id_name_mapping_static[xml_cache_key] ||= instance.id_name_mapping
66
+ @xmi_root_model_cache_static[xml_cache_key] ||= xmi_model
68
67
 
69
68
  ret_val
70
69
  end
71
-
72
- def deep_clone(obj)
73
- # TODO: we need this if xmi_model is being modified in serialize_generalization_by_name
74
- #Marshal.load(Marshal.dump(obj)) if obj != nil
75
- obj
76
- end
77
70
  end
78
71
 
79
72
  # @param xmi_model [Lutaml::Model::Serializable]
@@ -106,7 +99,7 @@ module Lutaml
106
99
  model = xmi_model.model
107
100
  options = {
108
101
  xmi_root_model: @xmi_root_model,
109
- xmi_cache: @xmi_cache,
102
+ id_name_mapping: @id_name_mapping,
110
103
  with_gen: true,
111
104
  with_absolute_path: true,
112
105
  }
@@ -116,14 +109,16 @@ module Lutaml
116
109
  # @param xmi_model [Lutaml::Model::Serializable]
117
110
  # @param name [String]
118
111
  # @param guidance_yaml [String]
112
+ # @param id_name_mapping [Hash]
119
113
  # @return [Hash]
120
- def serialize_generalization_by_name(xmi_model, name, # rubocop:disable Metrics/MethodLength
121
- guidance = nil, xmi_cache = nil)
122
- set_xmi_model(xmi_model, xmi_cache)
114
+ def serialize_generalization_by_name( # rubocop:disable Metrics/MethodLength
115
+ xmi_model, name, guidance = nil, id_name_mapping = nil
116
+ )
117
+ set_xmi_model(xmi_model, id_name_mapping)
123
118
  klass = find_klass_packaged_element(name)
124
119
  options = {
125
120
  xmi_root_model: @xmi_root_model,
126
- xmi_cache: @xmi_cache,
121
+ id_name_mapping: @id_name_mapping,
127
122
  with_gen: true,
128
123
  with_absolute_path: true,
129
124
  }
data/lib/lutaml/xmi.rb CHANGED
@@ -1,4 +1,3 @@
1
- require "lutaml/xmi/version"
2
1
  require "lutaml/xmi/parsers/xml"
3
2
  require "liquid"
4
3
  require "lutaml/path"
data/lutaml.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.required_ruby_version = ">= 2.7.0"
30
+ spec.required_ruby_version = ">= 2.7.0" # rubocop:disable Gemspec/RequiredRubyVersion
31
31
 
32
32
  spec.add_dependency "expressir", "~> 2.1.0"
33
33
  spec.add_dependency "hashie", "~> 4.1.0"
@@ -40,14 +40,6 @@ Gem::Specification.new do |spec|
40
40
  spec.add_dependency "parslet", "~> 2.0.0"
41
41
  spec.add_dependency "ruby-graphviz", "~> 1.2"
42
42
  spec.add_dependency "thor", "~> 1.0"
43
- spec.add_dependency "xmi", "~> 0.3.12"
44
-
45
- spec.add_development_dependency "byebug"
46
- spec.add_development_dependency "equivalent-xml", "~> 0.6.0"
47
- spec.add_development_dependency "pry", "~> 0.12.2"
48
- spec.add_development_dependency "rake", "~> 13.0"
49
- spec.add_development_dependency "rspec", "~> 3.11"
50
- spec.add_development_dependency "rubocop", "~> 1.58"
51
- spec.add_development_dependency "rubocop-performance", "~> 1.19"
43
+ spec.add_dependency "xmi", "~> 0.3.20"
52
44
  spec.metadata["rubygems_mfa_required"] = "true"
53
45
  end
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.32
4
+ version: 0.9.34
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-04-01 00:00:00.000000000 Z
11
+ date: 2025-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir
@@ -170,112 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - "~>"
172
172
  - !ruby/object:Gem::Version
173
- version: 0.3.12
173
+ version: 0.3.20
174
174
  type: :runtime
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - "~>"
179
179
  - !ruby/object:Gem::Version
180
- version: 0.3.12
181
- - !ruby/object:Gem::Dependency
182
- name: byebug
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: equivalent-xml
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - "~>"
200
- - !ruby/object:Gem::Version
201
- version: 0.6.0
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - "~>"
207
- - !ruby/object:Gem::Version
208
- version: 0.6.0
209
- - !ruby/object:Gem::Dependency
210
- name: pry
211
- requirement: !ruby/object:Gem::Requirement
212
- requirements:
213
- - - "~>"
214
- - !ruby/object:Gem::Version
215
- version: 0.12.2
216
- type: :development
217
- prerelease: false
218
- version_requirements: !ruby/object:Gem::Requirement
219
- requirements:
220
- - - "~>"
221
- - !ruby/object:Gem::Version
222
- version: 0.12.2
223
- - !ruby/object:Gem::Dependency
224
- name: rake
225
- requirement: !ruby/object:Gem::Requirement
226
- requirements:
227
- - - "~>"
228
- - !ruby/object:Gem::Version
229
- version: '13.0'
230
- type: :development
231
- prerelease: false
232
- version_requirements: !ruby/object:Gem::Requirement
233
- requirements:
234
- - - "~>"
235
- - !ruby/object:Gem::Version
236
- version: '13.0'
237
- - !ruby/object:Gem::Dependency
238
- name: rspec
239
- requirement: !ruby/object:Gem::Requirement
240
- requirements:
241
- - - "~>"
242
- - !ruby/object:Gem::Version
243
- version: '3.11'
244
- type: :development
245
- prerelease: false
246
- version_requirements: !ruby/object:Gem::Requirement
247
- requirements:
248
- - - "~>"
249
- - !ruby/object:Gem::Version
250
- version: '3.11'
251
- - !ruby/object:Gem::Dependency
252
- name: rubocop
253
- requirement: !ruby/object:Gem::Requirement
254
- requirements:
255
- - - "~>"
256
- - !ruby/object:Gem::Version
257
- version: '1.58'
258
- type: :development
259
- prerelease: false
260
- version_requirements: !ruby/object:Gem::Requirement
261
- requirements:
262
- - - "~>"
263
- - !ruby/object:Gem::Version
264
- version: '1.58'
265
- - !ruby/object:Gem::Dependency
266
- name: rubocop-performance
267
- requirement: !ruby/object:Gem::Requirement
268
- requirements:
269
- - - "~>"
270
- - !ruby/object:Gem::Version
271
- version: '1.19'
272
- type: :development
273
- prerelease: false
274
- version_requirements: !ruby/object:Gem::Requirement
275
- requirements:
276
- - - "~>"
277
- - !ruby/object:Gem::Version
278
- version: '1.19'
180
+ version: 0.3.20
279
181
  description: 'LutaML: data models in textual form'
280
182
  email:
281
183
  - open.source@ribose.com'
@@ -409,6 +311,7 @@ files:
409
311
  - lib/lutaml/xmi/liquid_drops/association_drop.rb
410
312
  - lib/lutaml/xmi/liquid_drops/attribute_drop.rb
411
313
  - lib/lutaml/xmi/liquid_drops/cardinality_drop.rb
314
+ - lib/lutaml/xmi/liquid_drops/connector_drop.rb
412
315
  - lib/lutaml/xmi/liquid_drops/constraint_drop.rb
413
316
  - lib/lutaml/xmi/liquid_drops/data_type_drop.rb
414
317
  - lib/lutaml/xmi/liquid_drops/diagram_drop.rb
@@ -420,9 +323,9 @@ files:
420
323
  - lib/lutaml/xmi/liquid_drops/operation_drop.rb
421
324
  - lib/lutaml/xmi/liquid_drops/package_drop.rb
422
325
  - lib/lutaml/xmi/liquid_drops/root_drop.rb
326
+ - lib/lutaml/xmi/liquid_drops/source_target_drop.rb
423
327
  - lib/lutaml/xmi/parsers/xmi_base.rb
424
328
  - lib/lutaml/xmi/parsers/xml.rb
425
- - lib/lutaml/xmi/version.rb
426
329
  - lib/lutaml/xml.rb
427
330
  - lib/lutaml/xml/parsers/xml.rb
428
331
  - lutaml.gemspec
@@ -1,5 +0,0 @@
1
- module Lutaml
2
- module XMI
3
- VERSION = "0.2.3"
4
- end
5
- end