xmi 0.3.6 → 0.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/xmi/ea_root.rb +66 -14
  3. data/lib/xmi/version.rb +1 -1
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 302b69df31217eb74d01a40473d3ed50a35af959c331be1424aadd2262759703
4
- data.tar.gz: 63d413fddf71518961876467bc6a87bd99686e3c3367f9e3510921c4047765da
3
+ metadata.gz: 9935af3e266be66b8cbcfc73865ee1edd574d46234e177e629b027a5db3870cc
4
+ data.tar.gz: 63ab08288740e703e14c9c0bf4a5aeebfc920430f4e0c58c6ab5b0a451d6dc52
5
5
  SHA512:
6
- metadata.gz: 4b484e2d65d687acb0671498f36929a5eaf30ef9275460ee0a66f716f38a5d088795dd9e5c10833e004d12304c1d544b8622c25fb88b79fcf5eb0a453ba9f267
7
- data.tar.gz: d4da102f2b81e27e0b4a8fd62817d3bf0ba2cb9b2e33dece2ccb56b21c9664af72e2df628a7e4e031799b03b699e284477520e39b07fe3cfd9a4c57663bce4e9
6
+ metadata.gz: 8c129eebe21bb4c182a72fca76b90e2868abaf78a10b1fadb1ff2e9d0055e09801f342275f7046955a497dfeb04a3a5e8640e12af154142cf5429f4216e368af
7
+ data.tar.gz: bc006ec3ef2dae3fdf4a076dc90763254b32a45d4517cc2bfdf4db1cb0596191533914f5a3b15294137c957f447c9ab8d6c6d80b81b6627f8029987dbbaa24db
data/lib/xmi/ea_root.rb CHANGED
@@ -202,7 +202,7 @@ module Xmi
202
202
  [apply_types_lines, apply_types_nodes]
203
203
  end
204
204
 
205
- def gen_generic_klass(node)
205
+ def gen_generic_klass(node, from_klass = nil) # rubocop:disable Metrics/MethodLength
206
206
  node_name = get_klass_name_from_node(node)
207
207
  attributes_lines, map_attributes_lines = gen_klass_tags(node)
208
208
  apply_types_lines, apply_types_nodes = gen_apply_types(node)
@@ -211,18 +211,34 @@ module Xmi
211
211
  apply_types_lines, apply_types_nodes
212
212
  )
213
213
 
214
+ map_attributes_lines = node_map_attributes(node_name,
215
+ from_klass, map_attributes_lines)
214
216
  xml_mapping = replace_xml_mapping(node_name, map_attributes_lines)
215
217
 
216
- replace_klass_template(node_name, attributes_lines, xml_mapping)
218
+ replace_klass_template(node_name, attributes_lines,
219
+ xml_mapping, from_klass)
217
220
  end
218
221
 
219
- def gen_klass_apply_types(attributes_lines, map_attributes_lines, apply_types_lines, apply_types_nodes)
222
+ def node_map_attributes(node_name, from_klass, map_attributes_lines)
223
+ if from_klass && @node_map.key?(from_klass.to_sym)
224
+ map_attributes_lines += @node_map[from_klass.to_sym].to_s
225
+ else
226
+ @node_map ||= {}
227
+ @node_map[node_name.to_sym] = map_attributes_lines
228
+ end
229
+
230
+ map_attributes_lines
231
+ end
232
+
233
+ def gen_klass_apply_types(attributes_lines, map_attributes_lines, apply_types_lines, apply_types_nodes) # rubocop:disable Metrics/MethodLength
220
234
  unless apply_types_nodes.empty?
221
235
  attributes_lines += apply_types_lines
222
236
  apply_types_nodes.each do |n|
223
237
  apply_types = n.attribute_nodes.map(&:value)
224
238
  apply_types.each do |apply_type|
225
- map_attributes_lines += gen_map_attribute_line("base_#{apply_type}", "base_#{apply_type}")
239
+ map_attributes_lines += gen_map_attribute_line(
240
+ "base_#{apply_type}", "base_#{apply_type}"
241
+ )
226
242
  end
227
243
  end
228
244
  end
@@ -251,9 +267,11 @@ module Xmi
251
267
  .rstrip
252
268
  end
253
269
 
254
- def replace_klass_template(node_name, attributes_lines, xml_mapping)
270
+ def replace_klass_template(node_name, attributes_lines, xml_mapping,
271
+ from_klass = nil)
255
272
  abstract_klass_name = get_klass_name_from_node(@abstract_klass_node)
256
- root_tag_line = "def self.root_tag; \"#{node_name}\"; end"
273
+ abstract_klass_name = from_klass if from_klass
274
+ root_tag_line = "def self.root_tag = \"#{node_name}\""
257
275
 
258
276
  KLASS_TEMPLATE
259
277
  .gsub("#KLASS_NAME#", Shale::Utils.classify(node_name))
@@ -267,6 +285,16 @@ module Xmi
267
285
  nodes = xmi_doc.xpath("//UMLProfiles//Stereotypes//Stereotype[not(contains(@isAbstract, 'true'))]")
268
286
  klasses_lines = ""
269
287
 
288
+ klasses_lines += "#{gen_generic_klasses_wo_base_stereotypes(nodes)}\n"
289
+ klasses_lines += "#{gen_generic_klasses_w_base_stereotypes(nodes)}\n"
290
+
291
+ klasses_lines
292
+ end
293
+
294
+ def gen_generic_klasses_wo_base_stereotypes(nodes)
295
+ nodes = nodes.select { |n| n.attributes["baseStereotypes"].nil? }
296
+ klasses_lines = ""
297
+
270
298
  nodes.each do |node|
271
299
  klasses_lines += "#{gen_generic_klass(node)}\n"
272
300
  end
@@ -274,6 +302,18 @@ module Xmi
274
302
  klasses_lines
275
303
  end
276
304
 
305
+ def gen_generic_klasses_w_base_stereotypes(nodes)
306
+ nodes = nodes.reject { |n| n.attributes["baseStereotypes"].nil? }
307
+ klasses_lines = ""
308
+
309
+ nodes.each do |node|
310
+ base_stereotypes = node.attributes["baseStereotypes"].value
311
+ klasses_lines += "#{gen_generic_klass(node, base_stereotypes)}\n"
312
+ end
313
+
314
+ klasses_lines
315
+ end
316
+
277
317
  def gen_klasses(xmi_doc)
278
318
  @abstract_klass_node = get_abstract_klass_node(xmi_doc)
279
319
  klasses_lines = ""
@@ -289,13 +329,8 @@ module Xmi
289
329
  end
290
330
 
291
331
  def get_namespace_from_definition(xmi_doc)
292
- node = xmi_doc.at_xpath("//UMLProfile/Documentation")
293
- namespace_key = node.attribute_nodes.find do |attr|
294
- attr.name == "name"
295
- end.value
296
- namespace_uri = node.attribute_nodes.find do |attr|
297
- attr.name == "URI"
298
- end.value
332
+ namespace_key = get_module_name_from_definition(xmi_doc)
333
+ namespace_uri = get_module_uri(xmi_doc)
299
334
 
300
335
  { name: namespace_key, uri: namespace_uri }
301
336
  end
@@ -308,7 +343,24 @@ module Xmi
308
343
  end
309
344
 
310
345
  def get_module_name(xmi_doc)
311
- xmi_doc.root.name.split(".").first.capitalize
346
+ get_module_name_from_definition(xmi_doc).capitalize
347
+ end
348
+
349
+ def get_module_name_from_definition(xmi_doc)
350
+ node = xmi_doc.at_xpath("//UMLProfile/Documentation")
351
+ node.attribute_nodes.find { |attr| attr.name == "name" }&.value
352
+ end
353
+
354
+ def get_module_uri(xmi_doc)
355
+ node = xmi_doc.at_xpath("//UMLProfile/Documentation")
356
+ uri = node.attribute_nodes.find { |attr| attr.name == "URI" }&.value
357
+
358
+ return uri if uri
359
+
360
+ name = get_module_name_from_definition(xmi_doc)
361
+ ver = node.attribute_nodes.find { |attr| attr.name == "version" }&.value
362
+
363
+ "http://www.sparxsystems.com/profiles/#{name}/#{ver}"
312
364
  end
313
365
  end
314
366
  end
data/lib/xmi/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Xmi
4
- VERSION = "0.3.6"
4
+ VERSION = "0.3.7"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xmi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.3.7
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-07-10 00:00:00.000000000 Z
11
+ date: 2024-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri