lutaml 0.9.31 → 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: 5fc853b658b666aa94375fab16effb961a032b3ef82bdc30b4c71945d8ed883c
4
- data.tar.gz: 9e7dd6cbcbb7376b2232ef014d5171e68716e3702882bc3316afc6b0e5b9e987
3
+ metadata.gz: 1a3e7ce554e5b58c9d922d7588087550e9fed056f5492e822b15531d91ddcb14
4
+ data.tar.gz: 18ee2a6d41c7056f56cbb8f869ca234e3fcff6688024f8aeff55797047069270
5
5
  SHA512:
6
- metadata.gz: c391071810d334c0bbf7e01b1680e5e7a3a425093df24fff2d52c45d05e6ad29fc69a2052d48192385e62918a38d33306f37e7f1376dcffbb1eb66affba82448
7
- data.tar.gz: 85aa4dfb062d83cbf8febca8e24cc912d43f29beaa690b4a1aa666de460320b04065a0d7332a1bb94a56c8480cb4602da29db7cb14c3780e49d9781c8a4067d2
6
+ metadata.gz: eb8d3699fc5cdda40ae70b388e520095874828d80d5759c32f754df0aff1ec31ae185f17296e26d09e23bb41c8326fb517626389227c277f549f6a107d303c17
7
+ data.tar.gz: 745883a9eea0ef04d31f6941121d15dc9b0a687ae9c55634bd6790ab5d12fd1e72e6b9ce8b128a992463c405b057de53db76d0d0518a412f673986a4928288b0
@@ -1,3 +1,3 @@
1
1
  module Lutaml
2
- VERSION = "0.9.31".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,18 +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?
32
- end
33
-
34
- # @param yaml [String]
28
+ # @param id_name_mapping [Hash]
35
29
  # @return [Hash]
36
- def get_guidance(yaml)
37
- return unless yaml
30
+ def set_xmi_model(xmi_model, id_name_mapping = nil)
31
+ @id_name_mapping ||= id_name_mapping || {}
32
+ @xmi_root_model ||= xmi_model
38
33
 
39
- YAML.safe_load(File.read(yaml, encoding: "UTF-8"))
34
+ if @id_name_mapping.empty?
35
+ map_id_name(@id_name_mapping, @xmi_root_model)
36
+ end
40
37
  end
41
38
 
42
39
  private
@@ -915,8 +912,8 @@ module Lutaml
915
912
  # @param xmi_id [String]
916
913
  # @return [String]
917
914
  def lookup_entity_name(xmi_id)
918
- model_node_name_by_xmi_id(xmi_id) if @xmi_cache.empty?
919
- @xmi_cache[xmi_id]
915
+ model_node_name_by_xmi_id(xmi_id) if @id_name_mapping.empty?
916
+ @id_name_mapping[xmi_id]
920
917
  end
921
918
 
922
919
  # @param xmi_id [String]
@@ -970,8 +967,8 @@ module Lutaml
970
967
  def model_node_name_by_xmi_id(xmi_id)
971
968
  id_name_mapping = Hash.new
972
969
  map_id_name(id_name_mapping, @xmi_root_model)
973
- @xmi_cache = id_name_mapping
974
- @xmi_cache[xmi_id]
970
+ @id_name_mapping = id_name_mapping
971
+ @id_name_mapping[xmi_id]
975
972
  end
976
973
 
977
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]
@@ -101,31 +94,31 @@ module Lutaml
101
94
  # @param xmi_model [Lutaml::Model::Serializable]
102
95
  # @param guidance_yaml [String]
103
96
  # return [Liquid::Drop]
104
- def serialize_xmi_to_liquid(xmi_model, guidance_yaml = nil)
97
+ def serialize_xmi_to_liquid(xmi_model, guidance = nil)
105
98
  set_xmi_model(xmi_model)
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
  }
113
- guidance = get_guidance(guidance_yaml)
114
106
  ::Lutaml::XMI::RootDrop.new(model, guidance, options)
115
107
  end
116
108
 
117
109
  # @param xmi_model [Lutaml::Model::Serializable]
118
110
  # @param name [String]
119
111
  # @param guidance_yaml [String]
112
+ # @param id_name_mapping [Hash]
120
113
  # @return [Hash]
121
- def serialize_generalization_by_name(xmi_model, name, # rubocop:disable Metrics/MethodLength
122
- guidance_yaml = nil, xmi_cache = nil)
123
- 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)
124
118
  klass = find_klass_packaged_element(name)
125
- guidance = get_guidance(guidance_yaml)
126
119
  options = {
127
120
  xmi_root_model: @xmi_root_model,
128
- xmi_cache: @xmi_cache,
121
+ id_name_mapping: @id_name_mapping,
129
122
  with_gen: true,
130
123
  with_absolute_path: true,
131
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.31
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-03-20 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