xmi 0.3.5 → 0.3.7

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: cf6faff1b8093081d01e1a58aa0f226c3803855f8ff172759708e87afd046454
4
- data.tar.gz: 14a1169f7ea7294d7b6e995bc631432ed222dd98785e5ecd928788135c095a0f
3
+ metadata.gz: 9935af3e266be66b8cbcfc73865ee1edd574d46234e177e629b027a5db3870cc
4
+ data.tar.gz: 63ab08288740e703e14c9c0bf4a5aeebfc920430f4e0c58c6ab5b0a451d6dc52
5
5
  SHA512:
6
- metadata.gz: 89bef5249d1599e1b15a9b30b8a81a51b8a804aad1747705370ec17b21d70205b2680630ecda4308b85252fed01cbca548de2764c9bbef296fc951f29ebcfd6d
7
- data.tar.gz: 72245cd81433e6d6942b7b7a3448d8008b5523524bc1dad0b8537fdceb57e8981a747e3e7f4e44d70c12514cf9869d9876425eafce0692d5a00f28d3de0ecb10
6
+ metadata.gz: 8c129eebe21bb4c182a72fca76b90e2868abaf78a10b1fadb1ff2e9d0055e09801f342275f7046955a497dfeb04a3a5e8640e12af154142cf5429f4216e368af
7
+ data.tar.gz: bc006ec3ef2dae3fdf4a076dc90763254b32a45d4517cc2bfdf4db1cb0596191533914f5a3b15294137c957f447c9ab8d6c6d80b81b6627f8029987dbbaa24db
data/lib/xmi/ea_root.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ Dir[File.join(__dir__, "extensions", "*.rb")].each { |file| require file }
4
+
3
5
  require "nokogiri"
4
6
 
5
7
  module Xmi
@@ -200,7 +202,7 @@ module Xmi
200
202
  [apply_types_lines, apply_types_nodes]
201
203
  end
202
204
 
203
- def gen_generic_klass(node)
205
+ def gen_generic_klass(node, from_klass = nil) # rubocop:disable Metrics/MethodLength
204
206
  node_name = get_klass_name_from_node(node)
205
207
  attributes_lines, map_attributes_lines = gen_klass_tags(node)
206
208
  apply_types_lines, apply_types_nodes = gen_apply_types(node)
@@ -209,18 +211,34 @@ module Xmi
209
211
  apply_types_lines, apply_types_nodes
210
212
  )
211
213
 
214
+ map_attributes_lines = node_map_attributes(node_name,
215
+ from_klass, map_attributes_lines)
212
216
  xml_mapping = replace_xml_mapping(node_name, map_attributes_lines)
213
217
 
214
- replace_klass_template(node_name, attributes_lines, xml_mapping)
218
+ replace_klass_template(node_name, attributes_lines,
219
+ xml_mapping, from_klass)
220
+ end
221
+
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
215
231
  end
216
232
 
217
- def gen_klass_apply_types(attributes_lines, map_attributes_lines, apply_types_lines, apply_types_nodes)
233
+ def gen_klass_apply_types(attributes_lines, map_attributes_lines, apply_types_lines, apply_types_nodes) # rubocop:disable Metrics/MethodLength
218
234
  unless apply_types_nodes.empty?
219
235
  attributes_lines += apply_types_lines
220
236
  apply_types_nodes.each do |n|
221
237
  apply_types = n.attribute_nodes.map(&:value)
222
238
  apply_types.each do |apply_type|
223
- 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
+ )
224
242
  end
225
243
  end
226
244
  end
@@ -249,9 +267,11 @@ module Xmi
249
267
  .rstrip
250
268
  end
251
269
 
252
- 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)
253
272
  abstract_klass_name = get_klass_name_from_node(@abstract_klass_node)
254
- 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}\""
255
275
 
256
276
  KLASS_TEMPLATE
257
277
  .gsub("#KLASS_NAME#", Shale::Utils.classify(node_name))
@@ -265,6 +285,16 @@ module Xmi
265
285
  nodes = xmi_doc.xpath("//UMLProfiles//Stereotypes//Stereotype[not(contains(@isAbstract, 'true'))]")
266
286
  klasses_lines = ""
267
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
+
268
298
  nodes.each do |node|
269
299
  klasses_lines += "#{gen_generic_klass(node)}\n"
270
300
  end
@@ -272,6 +302,18 @@ module Xmi
272
302
  klasses_lines
273
303
  end
274
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
+
275
317
  def gen_klasses(xmi_doc)
276
318
  @abstract_klass_node = get_abstract_klass_node(xmi_doc)
277
319
  klasses_lines = ""
@@ -287,13 +329,8 @@ module Xmi
287
329
  end
288
330
 
289
331
  def get_namespace_from_definition(xmi_doc)
290
- node = xmi_doc.at_xpath("//UMLProfile/Documentation")
291
- namespace_key = node.attribute_nodes.find do |attr|
292
- attr.name == "name"
293
- end.value
294
- namespace_uri = node.attribute_nodes.find do |attr|
295
- attr.name == "URI"
296
- end.value
332
+ namespace_key = get_module_name_from_definition(xmi_doc)
333
+ namespace_uri = get_module_uri(xmi_doc)
297
334
 
298
335
  { name: namespace_key, uri: namespace_uri }
299
336
  end
@@ -306,7 +343,24 @@ module Xmi
306
343
  end
307
344
 
308
345
  def get_module_name(xmi_doc)
309
- 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}"
310
364
  end
311
365
  end
312
366
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Xmi
4
+ class EaRoot
5
+ module Eauml
6
+ class Import < Shale::Mapper
7
+ attribute :base_package_import, Shale::Type::String
8
+
9
+ xml do
10
+ root "import"
11
+
12
+ map_attribute "base_PackageImport", to: :base_package_import
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ Dir[File.join(__dir__, "ea_extensions", "*.rb")].each { |file| require file }
4
+
5
+ module Xmi
6
+ class EaRoot
7
+ module Gml
8
+ class ApplicationSchema < Shale::Mapper
9
+ attribute :version, Shale::Type::String
10
+ attribute :xsd_document, Shale::Type::String
11
+ attribute :xmlns, Shale::Type::String
12
+ attribute :target_namespace, Shale::Type::String
13
+ attribute :base_package, Shale::Type::String
14
+
15
+ xml do
16
+ root "ApplicationSchema"
17
+
18
+ map_attribute "version", to: :version
19
+ map_attribute "xsdDocument", to: :xsd_document
20
+ map_attribute "xmlns", to: :xmlns
21
+ map_attribute "targetNamespace", to: :target_namespace
22
+ map_attribute "base_Package", to: :base_package
23
+ end
24
+ end
25
+
26
+ class CodeList < Shale::Mapper
27
+ attribute :as_dictionary, Shale::Type::String
28
+ attribute :default_code_space, Shale::Type::String
29
+ attribute :base_class, Shale::Type::String
30
+
31
+ xml do
32
+ root "CodeList"
33
+
34
+ map_attribute "asDictionary", to: :as_dictionary
35
+ map_attribute "defaultCodeSpace", to: :default_code_space
36
+ map_attribute "base_Class", to: :base_class
37
+ end
38
+ end
39
+
40
+ class Property < Shale::Mapper
41
+ attribute :sequence_number, Shale::Type::String
42
+ attribute :base_property, Shale::Type::String
43
+
44
+ xml do
45
+ root "property"
46
+
47
+ map_attribute "sequenceNumber", to: :sequence_number
48
+ map_attribute "base_Property", to: :base_property
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
data/lib/xmi/sparx.rb CHANGED
@@ -946,13 +946,18 @@ module Xmi
946
946
  end
947
947
 
948
948
  module SparxRootAttributes
949
- def self.included(klass)
949
+ def self.included(klass) # rubocop:disable Metrics/MethodLength
950
950
  klass.class_eval do
951
951
  attribute :publication_date, SparxCustomProfilePublicationDate
952
952
  attribute :edition, SparxCustomProfileEdition
953
953
  attribute :number, SparxCustomProfileNumber
954
954
  attribute :year_version, SparxCustomProfileYearVersion
955
955
  attribute :modelica_parameter, SparxSysPhS
956
+
957
+ attribute :eauml_import, EaRoot::Eauml::Import, collection: true
958
+ attribute :gml_application_schema, EaRoot::Gml::ApplicationSchema, collection: true
959
+ attribute :gml_code_list, EaRoot::Gml::CodeList, collection: true
960
+ attribute :gml_property, EaRoot::Gml::Property, collection: true
956
961
  end
957
962
  end
958
963
  end
@@ -988,6 +993,18 @@ module Xmi
988
993
  map_element "ModelicaParameter", to: :modelica_parameter,
989
994
  namespace: "http://www.sparxsystems.com/profiles/SysPhS/1.0",
990
995
  prefix: "SysPhS"
996
+ map_element "import", to: :eauml_import,
997
+ namespace: "http://www.sparxsystems.com/profiles/EAUML/1.0",
998
+ prefix: "EAUML"
999
+ map_element "ApplicationSchema", to: :gml_application_schema,
1000
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1001
+ prefix: "GML"
1002
+ map_element "CodeList", to: :gml_code_list,
1003
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1004
+ prefix: "GML"
1005
+ map_element "property", to: :gml_property,
1006
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1007
+ prefix: "GML"
991
1008
  MAP
992
1009
 
993
1010
  @@mapping ||= @@default_mapping # rubocop:disable Style/ClassVars
@@ -1028,6 +1045,18 @@ module Xmi
1028
1045
  map_element "ModelicaParameter", to: :modelica_parameter,
1029
1046
  namespace: "http://www.sparxsystems.com/profiles/SysPhS/1.0",
1030
1047
  prefix: "SysPhS"
1048
+ map_element "import", to: :eauml_import,
1049
+ namespace: "http://www.sparxsystems.com/profiles/EAUML/1.0",
1050
+ prefix: "EAUML"
1051
+ map_element "ApplicationSchema", to: :gml_application_schema,
1052
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1053
+ prefix: "GML"
1054
+ map_element "CodeList", to: :gml_code_list,
1055
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1056
+ prefix: "GML"
1057
+ map_element "property", to: :gml_property,
1058
+ namespace: "http://www.sparxsystems.com/profiles/GML/1.0",
1059
+ prefix: "GML"
1031
1060
  MAP
1032
1061
 
1033
1062
  @@mapping ||= @@default_mapping # rubocop:disable Style/ClassVars
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.5"
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.5
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
@@ -132,6 +132,8 @@ files:
132
132
  - lib/xmi/documentation.rb
133
133
  - lib/xmi/ea_root.rb
134
134
  - lib/xmi/extension.rb
135
+ - lib/xmi/extensions/eauml.rb
136
+ - lib/xmi/extensions/gml.rb
135
137
  - lib/xmi/replace.rb
136
138
  - lib/xmi/root.rb
137
139
  - lib/xmi/root13.rb