lutaml 0.9.21 → 0.9.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lutaml/version.rb +1 -1
- data/lib/lutaml/xmi/liquid_drops/klass_drop.rb +6 -4
- data/lib/lutaml/xmi/liquid_drops/package_drop.rb +5 -0
- data/lib/lutaml/xmi/parsers/xml.rb +142 -19
- data/lib/lutaml/xmi.rb +1 -0
- data/lutaml.gemspec +12 -10
- metadata +31 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc862e1c9607a9696f2104ebcd0b3fc32fabe504c910612013be0e3e6a9a1e69
|
4
|
+
data.tar.gz: 41613d1428429a6e629406d1d755745146f0f34ca78af7373a967bec3338ebbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea914bab620f52b038b5c0c7778eac2b257e3fafceb1b4ca5d75d198c3f53d763943f808a22d5d0561874d059fe1f1b4a819ec614c23a873f01685049b0362a
|
7
|
+
data.tar.gz: 4b0f439ac81fbdc1239833dd92288cc213ce7b78f53050acabf443b4e87bc4e795ca89cbc56cac8b783bb037de8fc3afa2f10aede1a03069328d4b9530dd91b8
|
data/lib/lutaml/version.rb
CHANGED
@@ -7,11 +7,9 @@ module Lutaml
|
|
7
7
|
@model = model
|
8
8
|
@guidance = guidance
|
9
9
|
|
10
|
-
if guidance
|
11
|
-
c["name"]
|
12
|
-
end.include?(@model[:name])
|
10
|
+
if guidance
|
13
11
|
@klass_guidance = guidance["classes"].find do |klass|
|
14
|
-
klass["name"] ==
|
12
|
+
klass["name"] == name || klass["name"] == absolute_path
|
15
13
|
end
|
16
14
|
end
|
17
15
|
end
|
@@ -24,6 +22,10 @@ module Lutaml
|
|
24
22
|
@model[:name]
|
25
23
|
end
|
26
24
|
|
25
|
+
def absolute_path
|
26
|
+
"#{@model[:absolute_path]}::#{name}"
|
27
|
+
end
|
28
|
+
|
27
29
|
def package
|
28
30
|
::Lutaml::XMI::PackageDrop.new(@model[:package], @guidance)
|
29
31
|
end
|
@@ -6,6 +6,7 @@ module Lutaml
|
|
6
6
|
def initialize(model, guidance = nil) # rubocop:disable Lint/MissingSuper
|
7
7
|
@model = model
|
8
8
|
@guidance = guidance
|
9
|
+
|
9
10
|
@children_packages ||= packages.map do |pkg|
|
10
11
|
[pkg, pkg.packages, pkg.packages.map(&:children_packages)]
|
11
12
|
end.flatten.uniq
|
@@ -19,6 +20,10 @@ module Lutaml
|
|
19
20
|
@model[:name]
|
20
21
|
end
|
21
22
|
|
23
|
+
def absolute_path
|
24
|
+
@model[:absolute_path]
|
25
|
+
end
|
26
|
+
|
22
27
|
def klasses
|
23
28
|
@model[:classes].map do |klass|
|
24
29
|
::Lutaml::XMI::KlassDrop.new(klass, @guidance)
|
@@ -38,6 +38,7 @@ module Lutaml
|
|
38
38
|
|
39
39
|
# @param xml [String] path to xml
|
40
40
|
# @param name [String]
|
41
|
+
# @param guidance [String]
|
41
42
|
# @return [Hash]
|
42
43
|
def serialize_generalization_by_name(xml, name, guidance = nil)
|
43
44
|
xmi_model = get_xmi_model(xml)
|
@@ -69,17 +70,28 @@ module Lutaml
|
|
69
70
|
end
|
70
71
|
|
71
72
|
# @param xmi_model [Shale::Mapper]
|
73
|
+
# @param with_gen: [Boolean]
|
74
|
+
# @param with_absolute_path: [Boolean]
|
72
75
|
# return [Hash]
|
73
|
-
def serialize_xmi(xmi_model, with_gen: false)
|
76
|
+
def serialize_xmi(xmi_model, with_gen: false, with_absolute_path: false)
|
74
77
|
set_xmi_model(xmi_model)
|
75
|
-
serialize_to_hash(
|
78
|
+
serialize_to_hash(
|
79
|
+
xmi_model,
|
80
|
+
with_gen: with_gen,
|
81
|
+
with_absolute_path: with_absolute_path,
|
82
|
+
)
|
76
83
|
end
|
77
84
|
|
78
85
|
# @param xmi_model [Shale::Mapper]
|
86
|
+
# @param guidance_yaml [String]
|
79
87
|
# return [Liquid::Drop]
|
80
88
|
def serialize_xmi_to_liquid(xmi_model, guidance_yaml = nil)
|
81
89
|
set_xmi_model(xmi_model)
|
82
|
-
serialized_hash = serialize_xmi(
|
90
|
+
serialized_hash = serialize_xmi(
|
91
|
+
xmi_model,
|
92
|
+
with_gen: true,
|
93
|
+
with_absolute_path: true,
|
94
|
+
)
|
83
95
|
guidance = get_guidance(guidance_yaml)
|
84
96
|
::Lutaml::XMI::RootDrop.new(serialized_hash, guidance)
|
85
97
|
end
|
@@ -94,12 +106,13 @@ module Lutaml
|
|
94
106
|
|
95
107
|
# @param xmi_model [Shale::Mapper]
|
96
108
|
# @param name [String]
|
109
|
+
# @param guidance_yaml [String]
|
97
110
|
# @return [Hash]
|
98
111
|
def serialize_generalization_by_name(xmi_model, name,
|
99
112
|
guidance_yaml = nil)
|
100
113
|
set_xmi_model(xmi_model)
|
101
114
|
model = xmi_model.model
|
102
|
-
klass =
|
115
|
+
klass = find_klass_packaged_element(name)
|
103
116
|
serialized_hash = build_klass_hash(klass, model, with_gen: true)
|
104
117
|
guidance = get_guidance(guidance_yaml)
|
105
118
|
::Lutaml::XMI::KlassDrop.new(serialized_hash, guidance)
|
@@ -108,39 +121,73 @@ module Lutaml
|
|
108
121
|
private
|
109
122
|
|
110
123
|
# @param xmi_model [Shale::Mapper]
|
124
|
+
# @param with_gen: [Boolean]
|
125
|
+
# @param with_absolute_path: [Boolean]
|
111
126
|
# @return [Hash]
|
112
127
|
# @note xpath: //uml:Model[@xmi:type="uml:Model"]
|
113
|
-
def serialize_to_hash(xmi_model,
|
128
|
+
def serialize_to_hash(xmi_model,
|
129
|
+
with_gen: false, with_absolute_path: false)
|
114
130
|
model = xmi_model.model
|
115
131
|
{
|
116
132
|
name: model.name,
|
117
|
-
packages: serialize_model_packages(
|
133
|
+
packages: serialize_model_packages(
|
134
|
+
model,
|
135
|
+
with_gen: with_gen,
|
136
|
+
with_absolute_path: with_absolute_path,
|
137
|
+
),
|
118
138
|
}
|
119
139
|
end
|
120
140
|
|
121
141
|
# @param model [Shale::Mapper]
|
142
|
+
# @param with_gen: [Boolean]
|
143
|
+
# @param with_absolute_path: [Boolean]
|
144
|
+
# @param absolute_path: [String]
|
122
145
|
# @return [Array<Hash>]
|
123
146
|
# @note xpath ./packagedElement[@xmi:type="uml:Package"]
|
124
|
-
def serialize_model_packages(model,
|
125
|
-
|
147
|
+
def serialize_model_packages(model, # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
148
|
+
with_gen: false, with_absolute_path: false, absolute_path: "")
|
149
|
+
packages = model.packaged_element.select do |e|
|
126
150
|
e.type?("uml:Package")
|
127
|
-
end
|
128
|
-
|
151
|
+
end
|
152
|
+
|
153
|
+
if with_absolute_path
|
154
|
+
absolute_path = "#{absolute_path}::#{model.name}"
|
155
|
+
end
|
156
|
+
|
157
|
+
packages.map do |package|
|
158
|
+
h = {
|
129
159
|
xmi_id: package.id,
|
130
160
|
name: get_package_name(package),
|
131
|
-
classes: serialize_model_classes(
|
132
|
-
|
161
|
+
classes: serialize_model_classes(
|
162
|
+
package, model,
|
163
|
+
with_gen: with_gen,
|
164
|
+
with_absolute_path: with_absolute_path,
|
165
|
+
absolute_path: "#{absolute_path}::#{package.name}"
|
166
|
+
),
|
133
167
|
enums: serialize_model_enums(package),
|
134
168
|
data_types: serialize_model_data_types(package),
|
135
169
|
diagrams: serialize_model_diagrams(package.id),
|
136
|
-
packages: serialize_model_packages(
|
170
|
+
packages: serialize_model_packages(
|
171
|
+
package,
|
172
|
+
with_gen: with_gen,
|
173
|
+
with_absolute_path: with_absolute_path,
|
174
|
+
absolute_path: absolute_path,
|
175
|
+
),
|
137
176
|
definition: doc_node_attribute_value(package.id, "documentation"),
|
138
177
|
stereotype: doc_node_attribute_value(package.id, "stereotype"),
|
139
178
|
}
|
179
|
+
|
180
|
+
if with_absolute_path
|
181
|
+
h[:absolute_path] = "#{absolute_path}::#{package.name}"
|
182
|
+
end
|
183
|
+
|
184
|
+
h
|
140
185
|
end
|
141
186
|
end
|
142
187
|
|
143
|
-
|
188
|
+
# @param package [Shale::Mapper]
|
189
|
+
# @return [String]
|
190
|
+
def get_package_name(package) # rubocop:disable Metrics/AbcSize
|
144
191
|
return package.name unless package.name.nil?
|
145
192
|
|
146
193
|
connector = fetch_connector(package.id)
|
@@ -154,22 +201,37 @@ module Lutaml
|
|
154
201
|
|
155
202
|
# @param package [Shale::Mapper]
|
156
203
|
# @param model [Shale::Mapper]
|
204
|
+
# @param with_gen: [Boolean]
|
205
|
+
# @param with_absolute_path: [Boolean]
|
157
206
|
# @return [Array<Hash>]
|
158
207
|
# @note xpath ./packagedElement[@xmi:type="uml:Class" or
|
159
208
|
# @xmi:type="uml:AssociationClass"]
|
160
|
-
def serialize_model_classes(package, model,
|
161
|
-
|
209
|
+
def serialize_model_classes(package, model, # rubocop:disable Metrics/MethodLength
|
210
|
+
with_gen: false, with_absolute_path: false, absolute_path: "")
|
211
|
+
klasses = package.packaged_element.select do |e|
|
162
212
|
e.type?("uml:Class") || e.type?("uml:AssociationClass") ||
|
163
213
|
e.type?("uml:Interface")
|
164
|
-
end
|
165
|
-
|
214
|
+
end
|
215
|
+
|
216
|
+
klasses.map do |klass|
|
217
|
+
h = build_klass_hash(
|
218
|
+
klass, model,
|
219
|
+
with_gen: with_gen
|
220
|
+
)
|
221
|
+
|
222
|
+
h[:absolute_path] = absolute_path if with_absolute_path
|
223
|
+
|
224
|
+
h
|
166
225
|
end
|
167
226
|
end
|
168
227
|
|
169
228
|
# @param klass [Shale::Mapper]
|
170
229
|
# @param model [Shale::Mapper]
|
230
|
+
# @param with_gen: [Boolean]
|
231
|
+
# @param with_absolute_path: [Boolean]
|
171
232
|
# @return [Hash]
|
172
|
-
def build_klass_hash(klass, model,
|
233
|
+
def build_klass_hash(klass, model, # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
|
234
|
+
with_gen: false, with_absolute_path: false, absolute_path: "")
|
173
235
|
klass_hash = {
|
174
236
|
xmi_id: klass.id,
|
175
237
|
name: klass.name,
|
@@ -184,6 +246,8 @@ module Lutaml
|
|
184
246
|
stereotype: doc_node_attribute_value(klass.id, "stereotype"),
|
185
247
|
}
|
186
248
|
|
249
|
+
klass_hash[:absolute_path] = absolute_path if with_absolute_path
|
250
|
+
|
187
251
|
if with_gen && klass.type?("uml:Class")
|
188
252
|
klass_hash[:generalization] = serialize_generalization(klass)
|
189
253
|
end
|
@@ -308,6 +372,65 @@ module Lutaml
|
|
308
372
|
upper_klass&.name
|
309
373
|
end
|
310
374
|
|
375
|
+
# @param path [String]
|
376
|
+
# @return [Shale::Mapper]
|
377
|
+
def find_klass_packaged_element(path)
|
378
|
+
lutaml_path = Lutaml::Path.parse(path)
|
379
|
+
if lutaml_path.segments.count == 1
|
380
|
+
return find_klass_packaged_element_by_name(path)
|
381
|
+
end
|
382
|
+
|
383
|
+
find_klass_packaged_element_by_path(lutaml_path)
|
384
|
+
end
|
385
|
+
|
386
|
+
# @param path [Lutaml::Path::ElementPath]
|
387
|
+
# @return [Shale::Mapper]
|
388
|
+
def find_klass_packaged_element_by_path(path)
|
389
|
+
if path.absolute?
|
390
|
+
iterate_packaged_element(
|
391
|
+
@xmi_root_model.model, path.segments.map(&:name)
|
392
|
+
)
|
393
|
+
else
|
394
|
+
iterate_relative_packaged_element(path.segments.map(&:name))
|
395
|
+
end
|
396
|
+
end
|
397
|
+
|
398
|
+
# @param name_array [Array<String>]
|
399
|
+
# @return [Shale::Mapper]
|
400
|
+
def iterate_relative_packaged_element(name_array)
|
401
|
+
# match the first element in the name_array
|
402
|
+
matched_elements = all_packaged_elements.select do |e|
|
403
|
+
e.type?("uml:Package") && e.name == name_array[0]
|
404
|
+
end
|
405
|
+
|
406
|
+
# match the rest elements in the name_array
|
407
|
+
result = matched_elements.map do |e|
|
408
|
+
iterate_packaged_element(e, name_array, type: "uml:Class")
|
409
|
+
end
|
410
|
+
|
411
|
+
result.compact.first
|
412
|
+
end
|
413
|
+
|
414
|
+
# @param model [Shale::Mapper]
|
415
|
+
# @param name_array [Array<String>]
|
416
|
+
# @param index: [Integer]
|
417
|
+
# @param type: [String]
|
418
|
+
# @return [Shale::Mapper]
|
419
|
+
def iterate_packaged_element(model, name_array,
|
420
|
+
index: 1, type: "uml:Package")
|
421
|
+
return model if index == name_array.count
|
422
|
+
|
423
|
+
model = model.packaged_element.find do |p|
|
424
|
+
p.name == name_array[index] && p.type?(type)
|
425
|
+
end
|
426
|
+
|
427
|
+
return nil if model.nil?
|
428
|
+
|
429
|
+
index += 1
|
430
|
+
type = index == name_array.count - 1 ? "uml:Class" : "uml:Package"
|
431
|
+
iterate_packaged_element(model, name_array, index: index, type: type)
|
432
|
+
end
|
433
|
+
|
311
434
|
# @param name [String]
|
312
435
|
# @return [Shale::Mapper]
|
313
436
|
def find_klass_packaged_element_by_name(name)
|
data/lib/lutaml/xmi.rb
CHANGED
data/lutaml.gemspec
CHANGED
@@ -29,15 +29,16 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.required_ruby_version = ">= 2.7.0"
|
31
31
|
|
32
|
-
spec.
|
33
|
-
spec.
|
34
|
-
spec.
|
35
|
-
spec.
|
36
|
-
spec.
|
37
|
-
spec.
|
38
|
-
spec.
|
39
|
-
spec.
|
40
|
-
spec.
|
32
|
+
spec.add_dependency "expressir", "~> 1.3"
|
33
|
+
spec.add_dependency "hashie", "~> 4.1.0"
|
34
|
+
spec.add_dependency "htmlentities"
|
35
|
+
spec.add_dependency "liquid"
|
36
|
+
spec.add_dependency "lutaml-path"
|
37
|
+
spec.add_dependency "nokogiri", "~> 1.10"
|
38
|
+
spec.add_dependency "parslet", "~> 2.0.0"
|
39
|
+
spec.add_dependency "ruby-graphviz", "~> 1.2"
|
40
|
+
spec.add_dependency "thor", "~> 1.0"
|
41
|
+
spec.add_dependency "xmi", "~> 0.3.10"
|
41
42
|
|
42
43
|
spec.add_development_dependency "byebug"
|
43
44
|
spec.add_development_dependency "equivalent-xml", "~> 0.6.0"
|
@@ -46,4 +47,5 @@ Gem::Specification.new do |spec|
|
|
46
47
|
spec.add_development_dependency "rspec", "~> 3.11"
|
47
48
|
spec.add_development_dependency "rubocop", "~> 1.58"
|
48
49
|
spec.add_development_dependency "rubocop-performance", "~> 1.19"
|
49
|
-
|
50
|
+
spec.metadata["rubygems_mfa_required"] = "true"
|
51
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lutaml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.23
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-11-
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: liquid
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - ">="
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - ">="
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '0'
|
27
13
|
- !ruby/object:Gem::Dependency
|
28
14
|
name: expressir
|
29
15
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +52,34 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: liquid
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: lutaml-path
|
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: nokogiri
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -396,6 +410,7 @@ metadata:
|
|
396
410
|
homepage_uri: https://github.com/lutaml/lutaml
|
397
411
|
source_code_uri: https://github.com/lutaml/lutaml
|
398
412
|
changelog_uri: https://github.com/lutaml/lutaml/releases
|
413
|
+
rubygems_mfa_required: 'true'
|
399
414
|
post_install_message:
|
400
415
|
rdoc_options: []
|
401
416
|
require_paths:
|