xmi 0.3.4 → 0.3.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa0a37c2b3b4d95e09706d9c2a3dee947622edd45342ed735c1fe346ef325929
4
- data.tar.gz: f3ce4cdb7dd6dd3fdda0478013f3ce87d4de70f400ec45f0c3b3a5388aaa1e15
3
+ metadata.gz: 302b69df31217eb74d01a40473d3ed50a35af959c331be1424aadd2262759703
4
+ data.tar.gz: 63d413fddf71518961876467bc6a87bd99686e3c3367f9e3510921c4047765da
5
5
  SHA512:
6
- metadata.gz: 243e5f497c1093cc90018d20b8a436239c8d535e4073aafc41d9af11a22c1f3eb06306854bbe0f59a74d4fbc0e036943bfa4a34c59a4ba8c046d5a595ee4301c
7
- data.tar.gz: 27167737fd6433c5e3e927b1454754c4b85e5ffe7bc31fc719ae53e3cb0e0e7ca7899c1745e6e51f867803f35c28c254c909a509f398ea4379b1454d057dc322
6
+ metadata.gz: 4b484e2d65d687acb0671498f36929a5eaf30ef9275460ee0a66f716f38a5d088795dd9e5c10833e004d12304c1d544b8622c25fb88b79fcf5eb0a453ba9f267
7
+ data.tar.gz: d4da102f2b81e27e0b4a8fd62817d3bf0ba2cb9b2e33dece2ccb56b21c9664af72e2df628a7e4e031799b03b699e284477520e39b07fe3cfd9a4c57663bce4e9
data/.gitignore CHANGED
@@ -9,3 +9,6 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ .ruby-version
13
+ .vscode
14
+ Gemfile.lock
data/README.adoc CHANGED
@@ -42,20 +42,20 @@ xmi_root_model = Xmi::Sparx::SparxRoot2013.from_xml(xml_content)
42
42
 
43
43
  This method takes the path to an XMI file and generate the Ruby objects.
44
44
 
45
- === Loading MDG Extensions and Generate Ruby Classes and Modules Dynamically
45
+ === Loading Extensions and Generate Ruby Classes and Modules Dynamically
46
46
 
47
- To load an MDG extension from an XML file, use the `load_mdg_extension` method:
47
+ To load an extension from an XML file, use the `load_extension` method:
48
48
 
49
49
  [source,ruby]
50
50
  ----
51
- Xmi::EaRoot.load_mdg_extension("path/to/your/mdg_extension.xml")
51
+ Xmi::EaRoot.load_extension("path/to/your/extension.xml")
52
52
 
53
53
  xml = "path/to/your/file.xmi"
54
54
  xml_content = File.read(xml)
55
55
  xmi_root_model = Xmi::Sparx::SparxRoot2013.from_xml(xml_content)
56
56
  ----
57
57
 
58
- `Xmi::EaRoot.load_mdg_extension` takes the path to an XML file and generate the
58
+ `Xmi::EaRoot.load_extension` takes the path to an XML file and generate the
59
59
  Ruby classes and modules defined in XML file dynamically.
60
60
  Then, you can generate Ruby objects by `Xmi::Sparx::SparxRoot2013.from_xml`.
61
61
 
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
@@ -45,17 +47,10 @@ module Xmi
45
47
  TEXT
46
48
 
47
49
  class << self
48
- def load_mdg_extension(xml_path)
49
- options = {}
50
- options[:input_xml_path] = xml_path
51
- options[:module_name] = "Mdg"
52
- load_extension(options)
53
- update_mdg_mappings
54
- end
55
-
56
- def load_extension(options)
57
- @content = gen_content(options)
50
+ def load_extension(xml_path)
51
+ @content = gen_content(xml_path)
58
52
  Object.class_eval @content
53
+ update_mappings(@module_name)
59
54
  end
60
55
 
61
56
  def output_rb_file(output_rb_path)
@@ -64,35 +59,35 @@ module Xmi
64
59
 
65
60
  private
66
61
 
67
- def update_mdg_mappings
68
- mdg_klasses = all_mdg_klasses
69
- map_elements = construct_shale_xml_mappings(mdg_klasses)
62
+ def update_mappings(module_name)
63
+ new_klasses = all_new_klasses(module_name)
64
+ map_elements = construct_shale_xml_mappings(new_klasses, module_name)
70
65
  sparx_roots.each do |sparx_root|
71
- update_shale_attributes(mdg_klasses, sparx_root)
66
+ update_shale_attributes(new_klasses, sparx_root, module_name)
72
67
  update_shale_xml_mappings(map_elements, sparx_root)
73
68
  end
74
69
  end
75
70
 
76
- def construct_shale_xml_mappings(mdg_klasses)
71
+ def construct_shale_xml_mappings(new_klasses, module_name) # rubocop:disable Metrics/MethodLength
77
72
  map_elements = []
78
- mdg_klasses.each do |klass|
79
- next unless Xmi::EaRoot::Mdg.const_get(klass).respond_to? :root_tag
73
+ new_klasses.each do |klass|
74
+ next unless Xmi::EaRoot.const_get(module_name).const_get(klass)
75
+ .respond_to? :root_tag
80
76
 
81
77
  map_elements << MAP_ELEMENT
82
- .gsub("#ELEMENT_NAME#", Xmi::EaRoot::Mdg.const_get(klass).root_tag)
78
+ .gsub("#ELEMENT_NAME#", Xmi::EaRoot.const_get(module_name).const_get(klass).root_tag)
83
79
  .gsub("#ELEMENT_METHOD#", Shale::Utils.snake_case(klass.to_s))
84
- .gsub("#NAMESPACE#", @mdg_namespace[:uri])
85
- .gsub("#PREFIX#", @mdg_namespace[:name])
80
+ .gsub("#NAMESPACE#", @def_namespace[:uri])
81
+ .gsub("#PREFIX#", @def_namespace[:name])
86
82
  end
87
83
 
88
84
  map_elements
89
85
  end
90
86
 
91
- def update_shale_attributes(mdg_klasses, sparx_root)
92
- mdg_klasses.each do |klass|
87
+ def update_shale_attributes(new_klasses, sparx_root, module_name)
88
+ new_klasses.each do |klass|
93
89
  method_name = Shale::Utils.snake_case(klass)
94
- full_klass_name = "Xmi::EaRoot::Mdg::#{klass}"
95
-
90
+ full_klass_name = "Xmi::EaRoot::#{module_name}::#{klass}"
96
91
  attr_line = "#{ATTRIBUTE_LINE.rstrip}, collection: true"
97
92
  attr_line = attr_line
98
93
  .gsub("#TAG_NAME#", method_name)
@@ -118,9 +113,9 @@ module Xmi
118
113
  [Xmi::Sparx::SparxRoot, Xmi::Sparx::SparxRoot2013]
119
114
  end
120
115
 
121
- def all_mdg_klasses
122
- Xmi::EaRoot::Mdg.constants.select do |c|
123
- Xmi::EaRoot::Mdg.const_get(c).is_a? Class
116
+ def all_new_klasses(module_name)
117
+ Xmi::EaRoot.const_get(module_name).constants.select do |c|
118
+ Xmi::EaRoot.const_get(module_name).const_get(c).is_a? Class
124
119
  end
125
120
  end
126
121
 
@@ -131,6 +126,8 @@ module Xmi
131
126
  end
132
127
 
133
128
  def get_klass_name_from_node(node)
129
+ return Shale::Mapper.to_s unless node
130
+
134
131
  node.attribute_nodes.find { |attr| attr.name == "name" }.value
135
132
  end
136
133
 
@@ -172,7 +169,12 @@ module Xmi
172
169
  [attributes_lines, tags]
173
170
  end
174
171
 
175
- def gen_abstract_klass
172
+ def gen_abstract_klass # rubocop:disable Metrics/MethodLength
173
+ unless @abstract_klass_node
174
+ @abstract_tags = []
175
+ return ""
176
+ end
177
+
176
178
  attributes_lines = ""
177
179
  tags_lines, @abstract_tags = gen_tags(@abstract_klass_node)
178
180
  attributes_lines += tags_lines
@@ -266,12 +268,6 @@ module Xmi
266
268
  klasses_lines = ""
267
269
 
268
270
  nodes.each do |node|
269
- # check baseStereotypes is abstract class
270
- base_stereotypes = node.attribute_nodes.find do |attr|
271
- attr.name == "baseStereotypes" && attr.value == get_klass_name_from_node(@abstract_klass_node)
272
- end
273
- next if base_stereotypes.nil?
274
-
275
271
  klasses_lines += "#{gen_generic_klass(node)}\n"
276
272
  end
277
273
 
@@ -292,7 +288,7 @@ module Xmi
292
288
  .gsub("#KLASSES#", gen_klasses(xmi_doc))
293
289
  end
294
290
 
295
- def get_mdg_namespace(xmi_doc)
291
+ def get_namespace_from_definition(xmi_doc)
296
292
  node = xmi_doc.at_xpath("//UMLProfile/Documentation")
297
293
  namespace_key = node.attribute_nodes.find do |attr|
298
294
  attr.name == "name"
@@ -304,12 +300,15 @@ module Xmi
304
300
  { name: namespace_key, uri: namespace_uri }
305
301
  end
306
302
 
307
- def gen_content(options)
308
- xml = options[:input_xml_path]
309
- module_name = options[:module_name].capitalize
310
- xmi_doc = Nokogiri::XML(File.open(xml).read)
311
- @mdg_namespace = get_mdg_namespace(xmi_doc)
312
- gen_module(xmi_doc, module_name)
303
+ def gen_content(xml)
304
+ xmi_doc = Nokogiri::XML(File.read(xml))
305
+ @module_name = get_module_name(xmi_doc)
306
+ @def_namespace = get_namespace_from_definition(xmi_doc)
307
+ gen_module(xmi_doc, @module_name)
308
+ end
309
+
310
+ def get_module_name(xmi_doc)
311
+ xmi_doc.root.name.split(".").first.capitalize
313
312
  end
314
313
  end
315
314
  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
@@ -674,6 +674,16 @@ module Xmi
674
674
  end
675
675
  end
676
676
 
677
+ class SparxPrimitiveTypes2013 < Shale::Mapper
678
+ attribute :packaged_element, Uml::PackagedElement2013, collection: true
679
+
680
+ xml do
681
+ root "primitivetypes"
682
+
683
+ map_element "packagedElement", to: :packaged_element
684
+ end
685
+ end
686
+
677
687
  class SparxProfiles < Shale::Mapper
678
688
  attribute :profile, Uml::Profile, collection: true
679
689
 
@@ -786,6 +796,20 @@ module Xmi
786
796
  end
787
797
  end
788
798
 
799
+ class SparxEAStub < Shale::Mapper
800
+ attribute :id, Shale::Type::String
801
+ attribute :name, Shale::Type::String
802
+ attribute :uml_type, Shale::Type::String
803
+
804
+ xml do
805
+ root "diagrams"
806
+
807
+ map_attribute "id", to: :id, prefix: "xmi", namespace: "http://www.omg.org/spec/XMI/20131001"
808
+ map_attribute "name", to: :name
809
+ map_attribute "UMLType", to: :uml_type
810
+ end
811
+ end
812
+
789
813
  module SparxExtensionAttributes
790
814
  def self.included(klass) # rubocop:disable Metrics/MethodLength
791
815
  klass.class_eval do
@@ -799,8 +823,9 @@ module Xmi
799
823
  attribute :extender_id, Shale::Type::String
800
824
  attribute :elements, SparxElements
801
825
  attribute :connectors, SparxConnectors
802
- attribute :primitive_types, SparxPrimitiveTypes
826
+ attribute :primitive_types, SparxPrimitiveTypes2013
803
827
  attribute :diagrams, SparxDiagrams
828
+ attribute :ea_stub, SparxEAStub, collection: true
804
829
  end
805
830
  end
806
831
  end
@@ -826,6 +851,7 @@ module Xmi
826
851
  map_element "primitivetypes", to: :primitive_types
827
852
  map_element "profiles", to: :profiles
828
853
  map_element "diagrams", to: :diagrams
854
+ map_element "EAStub", to: :ea_stub
829
855
  end
830
856
  end
831
857
 
@@ -850,6 +876,7 @@ module Xmi
850
876
  map_element "primitivetypes", to: :primitive_types
851
877
  map_element "profiles", to: :profiles
852
878
  map_element "diagrams", to: :diagrams
879
+ map_element "EAStub", to: :ea_stub
853
880
  end
854
881
  end
855
882
 
@@ -919,13 +946,18 @@ module Xmi
919
946
  end
920
947
 
921
948
  module SparxRootAttributes
922
- def self.included(klass)
949
+ def self.included(klass) # rubocop:disable Metrics/MethodLength
923
950
  klass.class_eval do
924
951
  attribute :publication_date, SparxCustomProfilePublicationDate
925
952
  attribute :edition, SparxCustomProfileEdition
926
953
  attribute :number, SparxCustomProfileNumber
927
954
  attribute :year_version, SparxCustomProfileYearVersion
928
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
929
961
  end
930
962
  end
931
963
  end
@@ -961,6 +993,18 @@ module Xmi
961
993
  map_element "ModelicaParameter", to: :modelica_parameter,
962
994
  namespace: "http://www.sparxsystems.com/profiles/SysPhS/1.0",
963
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"
964
1008
  MAP
965
1009
 
966
1010
  @@mapping ||= @@default_mapping # rubocop:disable Style/ClassVars
@@ -1001,6 +1045,18 @@ module Xmi
1001
1045
  map_element "ModelicaParameter", to: :modelica_parameter,
1002
1046
  namespace: "http://www.sparxsystems.com/profiles/SysPhS/1.0",
1003
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"
1004
1060
  MAP
1005
1061
 
1006
1062
  @@mapping ||= @@default_mapping # rubocop:disable Style/ClassVars
data/lib/xmi/uml.rb CHANGED
@@ -649,6 +649,7 @@ module Xmi
649
649
  end
650
650
  end
651
651
 
652
+ # TODO: add attributes xmlns:uml and xmlns:xmi
652
653
  module ProfileAttributes
653
654
  def self.included(klass)
654
655
  klass.class_eval do
@@ -656,6 +657,8 @@ module Xmi
656
657
  attribute :package_import, PackageImport, collection: true
657
658
  attribute :id, Shale::Type::String
658
659
  attribute :name, Shale::Type::String
660
+ # attribute :xmi, Shale::Type::String
661
+ # attribute :uml, Shale::Type::String
659
662
  attribute :ns_prefix, Shale::Type::String
660
663
 
661
664
  # Is this an EA thing?
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.4"
4
+ VERSION = "0.3.6"
5
5
  end
data/xmi.gemspec CHANGED
@@ -34,10 +34,10 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "nokogiri"
35
35
  spec.add_runtime_dependency "shale"
36
36
 
37
- spec.add_development_dependency "equivalent-xml"
38
37
  spec.add_development_dependency "pry", "~> 0.12.2"
39
38
  spec.add_development_dependency "rake", "~> 13.0"
40
39
  spec.add_development_dependency "rspec", "~> 3.11"
40
+ spec.add_development_dependency "rspec-xml"
41
41
  spec.add_development_dependency "rubocop", "~> 1.58"
42
42
  # spec.add_development_dependency "xml-c14n"
43
43
  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.4
4
+ version: 0.3.6
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-02 00:00:00.000000000 Z
11
+ date: 2024-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -38,20 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: equivalent-xml
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: pry
57
43
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +80,20 @@ dependencies:
94
80
  - - "~>"
95
81
  - !ruby/object:Gem::Version
96
82
  version: '3.11'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec-xml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: rubocop
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -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