xmi 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.adoc +4 -4
- data/lib/xmi/ea_root.rb +38 -41
- data/lib/xmi/sparx.rb +28 -1
- data/lib/xmi/uml.rb +3 -0
- data/lib/xmi/version.rb +1 -1
- data/xmi.gemspec +1 -1
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6faff1b8093081d01e1a58aa0f226c3803855f8ff172759708e87afd046454
|
4
|
+
data.tar.gz: 14a1169f7ea7294d7b6e995bc631432ed222dd98785e5ecd928788135c095a0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89bef5249d1599e1b15a9b30b8a81a51b8a804aad1747705370ec17b21d70205b2680630ecda4308b85252fed01cbca548de2764c9bbef296fc951f29ebcfd6d
|
7
|
+
data.tar.gz: 72245cd81433e6d6942b7b7a3448d8008b5523524bc1dad0b8537fdceb57e8981a747e3e7f4e44d70c12514cf9869d9876425eafce0692d5a00f28d3de0ecb10
|
data/.gitignore
CHANGED
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
|
45
|
+
=== Loading Extensions and Generate Ruby Classes and Modules Dynamically
|
46
46
|
|
47
|
-
To load an
|
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.
|
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.
|
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
@@ -45,17 +45,10 @@ module Xmi
|
|
45
45
|
TEXT
|
46
46
|
|
47
47
|
class << self
|
48
|
-
def
|
49
|
-
|
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)
|
48
|
+
def load_extension(xml_path)
|
49
|
+
@content = gen_content(xml_path)
|
58
50
|
Object.class_eval @content
|
51
|
+
update_mappings(@module_name)
|
59
52
|
end
|
60
53
|
|
61
54
|
def output_rb_file(output_rb_path)
|
@@ -64,35 +57,35 @@ module Xmi
|
|
64
57
|
|
65
58
|
private
|
66
59
|
|
67
|
-
def
|
68
|
-
|
69
|
-
map_elements = construct_shale_xml_mappings(
|
60
|
+
def update_mappings(module_name)
|
61
|
+
new_klasses = all_new_klasses(module_name)
|
62
|
+
map_elements = construct_shale_xml_mappings(new_klasses, module_name)
|
70
63
|
sparx_roots.each do |sparx_root|
|
71
|
-
update_shale_attributes(
|
64
|
+
update_shale_attributes(new_klasses, sparx_root, module_name)
|
72
65
|
update_shale_xml_mappings(map_elements, sparx_root)
|
73
66
|
end
|
74
67
|
end
|
75
68
|
|
76
|
-
def construct_shale_xml_mappings(
|
69
|
+
def construct_shale_xml_mappings(new_klasses, module_name) # rubocop:disable Metrics/MethodLength
|
77
70
|
map_elements = []
|
78
|
-
|
79
|
-
next unless Xmi::EaRoot
|
71
|
+
new_klasses.each do |klass|
|
72
|
+
next unless Xmi::EaRoot.const_get(module_name).const_get(klass)
|
73
|
+
.respond_to? :root_tag
|
80
74
|
|
81
75
|
map_elements << MAP_ELEMENT
|
82
|
-
.gsub("#ELEMENT_NAME#", Xmi::EaRoot
|
76
|
+
.gsub("#ELEMENT_NAME#", Xmi::EaRoot.const_get(module_name).const_get(klass).root_tag)
|
83
77
|
.gsub("#ELEMENT_METHOD#", Shale::Utils.snake_case(klass.to_s))
|
84
|
-
.gsub("#NAMESPACE#", @
|
85
|
-
.gsub("#PREFIX#", @
|
78
|
+
.gsub("#NAMESPACE#", @def_namespace[:uri])
|
79
|
+
.gsub("#PREFIX#", @def_namespace[:name])
|
86
80
|
end
|
87
81
|
|
88
82
|
map_elements
|
89
83
|
end
|
90
84
|
|
91
|
-
def update_shale_attributes(
|
92
|
-
|
85
|
+
def update_shale_attributes(new_klasses, sparx_root, module_name)
|
86
|
+
new_klasses.each do |klass|
|
93
87
|
method_name = Shale::Utils.snake_case(klass)
|
94
|
-
full_klass_name = "Xmi::EaRoot
|
95
|
-
|
88
|
+
full_klass_name = "Xmi::EaRoot::#{module_name}::#{klass}"
|
96
89
|
attr_line = "#{ATTRIBUTE_LINE.rstrip}, collection: true"
|
97
90
|
attr_line = attr_line
|
98
91
|
.gsub("#TAG_NAME#", method_name)
|
@@ -118,9 +111,9 @@ module Xmi
|
|
118
111
|
[Xmi::Sparx::SparxRoot, Xmi::Sparx::SparxRoot2013]
|
119
112
|
end
|
120
113
|
|
121
|
-
def
|
122
|
-
Xmi::EaRoot
|
123
|
-
Xmi::EaRoot
|
114
|
+
def all_new_klasses(module_name)
|
115
|
+
Xmi::EaRoot.const_get(module_name).constants.select do |c|
|
116
|
+
Xmi::EaRoot.const_get(module_name).const_get(c).is_a? Class
|
124
117
|
end
|
125
118
|
end
|
126
119
|
|
@@ -131,6 +124,8 @@ module Xmi
|
|
131
124
|
end
|
132
125
|
|
133
126
|
def get_klass_name_from_node(node)
|
127
|
+
return Shale::Mapper.to_s unless node
|
128
|
+
|
134
129
|
node.attribute_nodes.find { |attr| attr.name == "name" }.value
|
135
130
|
end
|
136
131
|
|
@@ -172,7 +167,12 @@ module Xmi
|
|
172
167
|
[attributes_lines, tags]
|
173
168
|
end
|
174
169
|
|
175
|
-
def gen_abstract_klass
|
170
|
+
def gen_abstract_klass # rubocop:disable Metrics/MethodLength
|
171
|
+
unless @abstract_klass_node
|
172
|
+
@abstract_tags = []
|
173
|
+
return ""
|
174
|
+
end
|
175
|
+
|
176
176
|
attributes_lines = ""
|
177
177
|
tags_lines, @abstract_tags = gen_tags(@abstract_klass_node)
|
178
178
|
attributes_lines += tags_lines
|
@@ -266,12 +266,6 @@ module Xmi
|
|
266
266
|
klasses_lines = ""
|
267
267
|
|
268
268
|
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
269
|
klasses_lines += "#{gen_generic_klass(node)}\n"
|
276
270
|
end
|
277
271
|
|
@@ -292,7 +286,7 @@ module Xmi
|
|
292
286
|
.gsub("#KLASSES#", gen_klasses(xmi_doc))
|
293
287
|
end
|
294
288
|
|
295
|
-
def
|
289
|
+
def get_namespace_from_definition(xmi_doc)
|
296
290
|
node = xmi_doc.at_xpath("//UMLProfile/Documentation")
|
297
291
|
namespace_key = node.attribute_nodes.find do |attr|
|
298
292
|
attr.name == "name"
|
@@ -304,12 +298,15 @@ module Xmi
|
|
304
298
|
{ name: namespace_key, uri: namespace_uri }
|
305
299
|
end
|
306
300
|
|
307
|
-
def gen_content(
|
308
|
-
|
309
|
-
module_name =
|
310
|
-
|
311
|
-
|
312
|
-
|
301
|
+
def gen_content(xml)
|
302
|
+
xmi_doc = Nokogiri::XML(File.read(xml))
|
303
|
+
@module_name = get_module_name(xmi_doc)
|
304
|
+
@def_namespace = get_namespace_from_definition(xmi_doc)
|
305
|
+
gen_module(xmi_doc, @module_name)
|
306
|
+
end
|
307
|
+
|
308
|
+
def get_module_name(xmi_doc)
|
309
|
+
xmi_doc.root.name.split(".").first.capitalize
|
313
310
|
end
|
314
311
|
end
|
315
312
|
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,
|
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
|
|
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
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
|
+
version: 0.3.5
|
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-
|
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
|