lutaml 0.9.32 → 0.9.33

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: 41d6dc7f483284d84fd66c7fb2a22f4596ddc4079ecf0c9e380a5f4545a8952f
4
- data.tar.gz: 991540aa13eed6d834518df31ba567bed4b13049fd4abe1ba59a88a1afe94ca1
3
+ metadata.gz: 1a3e7ce554e5b58c9d922d7588087550e9fed056f5492e822b15531d91ddcb14
4
+ data.tar.gz: 18ee2a6d41c7056f56cbb8f869ca234e3fcff6688024f8aeff55797047069270
5
5
  SHA512:
6
- metadata.gz: 1893e415bfc169cd0e78602b6046b2b1f6475ad44c1aa60aad48810cda87cb9cc3f7e1fc372df6f275900ca05dfd3023e9b77ec91ba2e389dfa5385c55c8af56
7
- data.tar.gz: b7e8813e7a8f6b57659d6467e7fa09d03098b7c4e93c34c088147e96507b02cf7ee2212afdf9d7af6df02bd39b1a20aa6c9789eb047dd6ed0d1c1bff365aa8bd
6
+ metadata.gz: eb8d3699fc5cdda40ae70b388e520095874828d80d5759c32f754df0aff1ec31ae185f17296e26d09e23bb41c8326fb517626389227c277f549f6a107d303c17
7
+ data.tar.gz: 745883a9eea0ef04d31f6941121d15dc9b0a687ae9c55634bd6790ab5d12fd1e72e6b9ce8b128a992463c405b057de53db76d0d0518a412f673986a4928288b0
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.32".freeze
2
+ VERSION = "0.9.33".freeze
3
3
  end
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
 
14
14
  uml_type = @model.uml_type
15
15
  @uml_type_idref = uml_type.idref if uml_type
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
 
14
14
  @owned_attributes = model&.owned_attribute&.select do |attr|
15
15
  attr.type?("uml:Property")
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
  end
14
14
 
15
15
  def xmi_id
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
 
14
14
  @owned_literals = model&.owned_literal&.select do |owned_literal|
15
15
  owned_literal.type? "uml:EnumerationLiteral"
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
  end
14
14
 
15
15
  def name
@@ -13,7 +13,7 @@ module Lutaml
13
13
  @guidance = guidance
14
14
  @options = options
15
15
  @xmi_root_model = options[:xmi_root_model]
16
- @xmi_cache = options[:xmi_cache]
16
+ @id_name_mapping = options[:id_name_mapping]
17
17
  end
18
18
 
19
19
  def id
@@ -10,7 +10,7 @@ module Lutaml
10
10
  @guidance = guidance
11
11
  @options = options
12
12
  @xmi_root_model = options[:xmi_root_model]
13
- @xmi_cache = options[:xmi_cache]
13
+ @id_name_mapping = options[:id_name_mapping]
14
14
 
15
15
  @package = model&.packaged_element&.find do |e|
16
16
  e.type?("uml:Package")
@@ -9,7 +9,7 @@ module Lutaml
9
9
  @model = model
10
10
  @options = options
11
11
  @xmi_root_model = options[:xmi_root_model]
12
- @xmi_cache = options[:xmi_cache]
12
+ @id_name_mapping = options[:id_name_mapping]
13
13
  end
14
14
 
15
15
  def id
@@ -11,7 +11,7 @@ module Lutaml
11
11
 
12
12
  @options = options
13
13
  @xmi_root_model = options[:xmi_root_model]
14
- @xmi_cache = options[:xmi_cache]
14
+ @id_name_mapping = options[:id_name_mapping]
15
15
 
16
16
  @packages = model.packaged_element.select do |e|
17
17
  e.type?("uml:Package")
@@ -8,7 +8,7 @@ module Lutaml
8
8
  @guidance = guidance
9
9
  @options = options
10
10
  @xmi_root_model = options[:xmi_root_model]
11
- @xmi_cache = options[:xmi_cache]
11
+ @id_name_mapping = options[:id_name_mapping]
12
12
 
13
13
  @options[:absolute_path] = "::#{model.name}"
14
14
 
@@ -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
@@ -907,8 +912,8 @@ module Lutaml
907
912
  # @param xmi_id [String]
908
913
  # @return [String]
909
914
  def lookup_entity_name(xmi_id)
910
- model_node_name_by_xmi_id(xmi_id) if @xmi_cache.empty?
911
- @xmi_cache[xmi_id]
915
+ model_node_name_by_xmi_id(xmi_id) if @id_name_mapping.empty?
916
+ @id_name_mapping[xmi_id]
912
917
  end
913
918
 
914
919
  # @param xmi_id [String]
@@ -962,8 +967,8 @@ module Lutaml
962
967
  def model_node_name_by_xmi_id(xmi_id)
963
968
  id_name_mapping = Hash.new
964
969
  map_id_name(id_name_mapping, @xmi_root_model)
965
- @xmi_cache = id_name_mapping
966
- @xmi_cache[xmi_id]
970
+ @id_name_mapping = id_name_mapping
971
+ @id_name_mapping[xmi_id]
967
972
  end
968
973
 
969
974
  # @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
  }
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.33
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-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: expressir