lutaml-uml 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +36 -0
- data/.github/workflows/ubuntu.yml +38 -0
- data/.github/workflows/windows.yml +41 -0
- data/.gitignore +1 -0
- data/Gemfile +2 -1
- data/LUTAML.adoc +314 -0
- data/{README.md → README.adoc} +15 -16
- data/Rakefile +3 -1
- data/bin/console +1 -0
- data/bin/lutaml2dotpng +23 -0
- data/bin/yaml2lutaml +108 -0
- data/exe/lutaml-uml +4 -3
- data/lib/lutaml/layout/engine.rb +15 -0
- data/lib/lutaml/layout/graph_viz_engine.rb +16 -0
- data/lib/lutaml/uml.rb +3 -0
- data/lib/lutaml/uml/abstraction.rb +7 -5
- data/lib/lutaml/uml/activity.rb +7 -5
- data/lib/lutaml/uml/actor.rb +14 -12
- data/lib/lutaml/uml/association.rb +40 -14
- data/lib/lutaml/uml/behavior.rb +7 -5
- data/lib/lutaml/uml/class.rb +56 -16
- data/lib/lutaml/uml/classifier.rb +9 -6
- data/lib/lutaml/uml/connector.rb +16 -12
- data/lib/lutaml/uml/constraint.rb +8 -7
- data/lib/lutaml/uml/constructor_end.rb +11 -8
- data/lib/lutaml/uml/data_type.rb +9 -4
- data/lib/lutaml/uml/dependency.rb +16 -13
- data/lib/lutaml/uml/document.rb +71 -0
- data/lib/lutaml/uml/enum.rb +33 -0
- data/lib/lutaml/uml/event.rb +7 -5
- data/lib/lutaml/uml/final_state.rb +7 -5
- data/lib/lutaml/uml/formatter.rb +21 -0
- data/lib/lutaml/uml/formatter/base.rb +67 -0
- data/lib/lutaml/uml/formatter/graphviz.rb +335 -0
- data/lib/lutaml/uml/has_attributes.rb +14 -0
- data/lib/lutaml/uml/has_members.rb +30 -0
- data/lib/lutaml/uml/instance.rb +15 -10
- data/lib/lutaml/uml/interface/base.rb +28 -0
- data/lib/lutaml/uml/interface/command_line.rb +265 -0
- data/lib/lutaml/uml/model.rb +11 -8
- data/lib/lutaml/uml/node/base.rb +21 -0
- data/lib/lutaml/uml/node/class_node.rb +57 -0
- data/lib/lutaml/uml/node/class_relationship.rb +14 -0
- data/lib/lutaml/uml/node/document.rb +18 -0
- data/lib/lutaml/uml/node/field.rb +34 -0
- data/lib/lutaml/uml/node/has_name.rb +15 -0
- data/lib/lutaml/uml/node/has_type.rb +15 -0
- data/lib/lutaml/uml/node/method.rb +29 -0
- data/lib/lutaml/uml/node/method_argument.rb +16 -0
- data/lib/lutaml/uml/node/relationship.rb +28 -0
- data/lib/lutaml/uml/opaque_behavior.rb +7 -6
- data/lib/lutaml/uml/package.rb +16 -13
- data/lib/lutaml/uml/parsers/attribute.rb +70 -0
- data/lib/lutaml/uml/parsers/dsl.rb +375 -0
- data/lib/lutaml/uml/parsers/dsl_preprocessor.rb +44 -0
- data/lib/lutaml/uml/parsers/dsl_transform.rb +27 -0
- data/lib/lutaml/uml/parsers/yaml.rb +46 -0
- data/lib/lutaml/uml/port.rb +6 -4
- data/lib/lutaml/uml/primitive_type.rb +9 -4
- data/lib/lutaml/uml/property.rb +25 -15
- data/lib/lutaml/uml/pseudostate.rb +7 -6
- data/lib/lutaml/uml/realization.rb +7 -5
- data/lib/lutaml/uml/region.rb +7 -6
- data/lib/lutaml/uml/serializers/association.rb +58 -0
- data/lib/lutaml/uml/serializers/base.rb +16 -0
- data/lib/lutaml/uml/serializers/class.rb +29 -0
- data/lib/lutaml/uml/serializers/top_element_attribute.rb +14 -0
- data/lib/lutaml/uml/serializers/yaml_view.rb +18 -0
- data/lib/lutaml/uml/state.rb +8 -6
- data/lib/lutaml/uml/state_machine.rb +7 -5
- data/lib/lutaml/uml/top_element.rb +45 -35
- data/lib/lutaml/uml/top_element_attribute.rb +25 -0
- data/lib/lutaml/uml/transition.rb +8 -6
- data/lib/lutaml/uml/trigger.rb +8 -6
- data/lib/lutaml/uml/version.rb +3 -1
- data/lib/lutaml/uml/vertex.rb +7 -5
- data/lutaml-uml.gemspec +9 -2
- data/spec/fixtures/datamodel/models/AddressClassProfile.yml +90 -0
- data/spec/fixtures/datamodel/models/AddressComponentProfile.yml +63 -0
- data/spec/fixtures/datamodel/models/AddressComponentSpecification.yml +15 -0
- data/spec/fixtures/datamodel/models/AddressProfile.yml +36 -0
- data/spec/fixtures/datamodel/models/AttributeProfile.yml +32 -0
- data/spec/fixtures/datamodel/models/InterchangeAddressClassProfile.yml +79 -0
- data/spec/fixtures/datamodel/models/Localization copy.yml +23 -0
- data/spec/fixtures/datamodel/models/Localization.yml +23 -0
- data/spec/fixtures/datamodel/models/ProfileCompliantAddress.yml +36 -0
- data/spec/fixtures/datamodel/models/ProfileCompliantAddressComponent.yml +15 -0
- data/spec/fixtures/datamodel/models/Signature.yml +20 -0
- data/spec/fixtures/datamodel/models/SignatureBlankDefinition.yml +20 -0
- data/spec/fixtures/datamodel/models/TextDirectionCode copy.yml +16 -0
- data/spec/fixtures/datamodel/models/TextDirectionCode.yml +16 -0
- data/spec/fixtures/datamodel/models/Validity.yml +14 -0
- data/spec/fixtures/datamodel/models/iso19160-1/Address.yml +22 -0
- data/spec/fixtures/datamodel/models/iso19160-1/AddressComponent.yml +2 -0
- data/spec/fixtures/datamodel/style.uml.inc +37 -0
- data/spec/fixtures/datamodel/views/AddressClassProfile.yml +12 -0
- data/spec/fixtures/datamodel/views/AddressProfile.yml +3 -0
- data/spec/fixtures/datamodel/views/CommonModels.yml +9 -0
- data/spec/fixtures/datamodel/views/TopDown.yml +62 -0
- data/spec/fixtures/dsl/diagram.lutaml +3 -0
- data/spec/fixtures/dsl/diagram_attributes.lutaml +5 -0
- data/spec/fixtures/dsl/diagram_class_assocation.lutaml +29 -0
- data/spec/fixtures/dsl/diagram_class_fields.lutaml +19 -0
- data/spec/fixtures/dsl/diagram_comments.lutaml +28 -0
- data/spec/fixtures/dsl/diagram_concept_model.lutaml +132 -0
- data/spec/fixtures/dsl/diagram_data_types.lutaml +24 -0
- data/spec/fixtures/dsl/diagram_includes.lutaml +6 -0
- data/spec/fixtures/dsl/diagram_multiply_classes.lutaml +7 -0
- data/spec/fixtures/dsl/shared.lutaml +3 -0
- data/spec/fixtures/dsl/shared1.lutaml +4 -0
- data/spec/fixtures/generated_dot/AddressClassProfile.dot +170 -0
- data/spec/fixtures/generated_dot/AddressProfile.dot +34 -0
- data/spec/lutaml/uml/formatter/graphviz_spec.rb +41 -0
- data/spec/lutaml/uml/parsers/dsl_spec.rb +252 -0
- data/spec/lutaml/uml/parsers/yaml_spec.rb +18 -0
- data/spec/lutaml/uml/serializers/yaml_view_spec.rb +20 -0
- data/spec/lutaml/uml_spec.rb +2 -4
- data/spec/spec_helper.rb +11 -0
- metadata +161 -13
data/{README.md → README.adoc}
RENAMED
@@ -1,28 +1,27 @@
|
|
1
1
|
# Lutaml::Uml
|
2
2
|
|
3
|
-
|
3
|
+
Lutaml is a language for specifying UML class diagrams and a tool for converting it into various different formats.
|
4
4
|
|
5
|
-
|
5
|
+
## Install
|
6
6
|
|
7
|
-
|
7
|
+
### Bundler: `gem "lutaml-uml"`
|
8
8
|
|
9
|
-
|
9
|
+
### RubyGems: `gem install lutaml-uml`
|
10
10
|
|
11
|
-
|
12
|
-
gem 'lutaml-uml'
|
13
|
-
```
|
11
|
+
## Executable
|
14
12
|
|
15
|
-
|
13
|
+
[source,sh]
|
14
|
+
--
|
15
|
+
# Convert example.lutaml to example.png
|
16
|
+
$ lutaml-uml --type png --output . example.lutaml
|
16
17
|
|
17
|
-
|
18
|
+
# Display detailed help message
|
19
|
+
$ lutaml-uml --help
|
20
|
+
--
|
18
21
|
|
19
|
-
|
22
|
+
## Language
|
20
23
|
|
21
|
-
|
22
|
-
|
23
|
-
## Usage
|
24
|
-
|
25
|
-
TODO: Write usage instructions here
|
24
|
+
See link:LUTAML.adoc[LUTAML.adoc]
|
26
25
|
|
27
26
|
## Development
|
28
27
|
|
@@ -37,4 +36,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERN
|
|
37
36
|
|
38
37
|
## Code of Conduct
|
39
38
|
|
40
|
-
Everyone interacting in the Lutaml::Uml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lutaml-uml/blob/master/CODE_OF_CONDUCT.md).
|
39
|
+
Everyone interacting in the Lutaml::Uml project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/lutaml-uml/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
CHANGED
data/bin/console
CHANGED
data/bin/lutaml2dotpng
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# Script to convert lutaml files into dot and png files
|
6
|
+
# Usage: bin/lutaml2dotpng /path/to/lutaml/folder/
|
7
|
+
require "bundler/setup"
|
8
|
+
require "lutaml/uml"
|
9
|
+
|
10
|
+
basedir = ARGV[0]
|
11
|
+
Dir["#{basedir}/*.lutaml"].each do |filename|
|
12
|
+
puts(filename)
|
13
|
+
base_filename = File.basename(filename, '.lutaml')
|
14
|
+
File.open("#{basedir}/#{base_filename}.dot", 'w') do |file|
|
15
|
+
file
|
16
|
+
.puts(Lutaml::Uml::Formatter::Graphviz
|
17
|
+
.new
|
18
|
+
.format_document(
|
19
|
+
Lutaml::Uml::Parsers::Dsl
|
20
|
+
.parse(File.read("#{basedir}/#{base_filename}.lutaml"))))
|
21
|
+
end
|
22
|
+
`dot -T png #{"#{basedir}/#{base_filename}.dot"} > "#{basedir}/#{base_filename}.png"`
|
23
|
+
end
|
data/bin/yaml2lutaml
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# Script to convert datamodel yaml files into LutaML syntax
|
6
|
+
# Usage: bin/yaml2lutaml /path/to/datamodel/view/file.yml
|
7
|
+
|
8
|
+
require "yaml"
|
9
|
+
|
10
|
+
view_yaml = YAML.safe_load(File.read(ARGV[0]))
|
11
|
+
models_path = File.expand_path("../../models", ARGV[0])
|
12
|
+
|
13
|
+
def sync_puts(line, level = 0)
|
14
|
+
$stdout.puts("#{''.rjust(level)}#{line}")
|
15
|
+
$stdout.flush
|
16
|
+
end
|
17
|
+
|
18
|
+
encountered_relations = Hash.new { |h, key| h[key] = [] }
|
19
|
+
# relations:
|
20
|
+
# - target: AttributeProfile
|
21
|
+
# relationship:
|
22
|
+
# source:
|
23
|
+
# type: aggregation
|
24
|
+
# attribute:
|
25
|
+
# addressClassProfile:
|
26
|
+
# target:
|
27
|
+
# type: direct
|
28
|
+
# attribute:
|
29
|
+
# attributeProfile:
|
30
|
+
# cardinality:
|
31
|
+
# min: 0
|
32
|
+
# max: '*'
|
33
|
+
def process_association(owner, values, encountered_relations)
|
34
|
+
target_name = values["target"]
|
35
|
+
return if encountered_relations[owner].include?(target_name)
|
36
|
+
|
37
|
+
encountered_relations[owner].push(target_name)
|
38
|
+
sync_puts("association {", 2)
|
39
|
+
|
40
|
+
relationship_block = values["relationship"] || {}
|
41
|
+
|
42
|
+
if relationship_block["source"] && relationship_block["source"]["type"]
|
43
|
+
source = relationship_block["source"]
|
44
|
+
sync_puts("owner_type #{source['type']}", 4)
|
45
|
+
if source["attribute"]
|
46
|
+
source_attribute_name = source["attribute"].keys.first
|
47
|
+
owner += "##{source_attribute_name}"
|
48
|
+
if source["attribute"][source_attribute_name]["cardinality"]
|
49
|
+
cardinality = source["attribute"][source_attribute_name]["cardinality"]
|
50
|
+
owner += " [#{cardinality['min']}..#{cardinality['max']}]"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
sync_puts("owner #{owner}", 4)
|
55
|
+
|
56
|
+
member = target_name
|
57
|
+
if relationship_block["target"]
|
58
|
+
target = relationship_block["target"]
|
59
|
+
type = target["type"] || "direct"
|
60
|
+
sync_puts("member_type #{type}", 4)
|
61
|
+
if target["attribute"]
|
62
|
+
target_attribute_name = target["attribute"].keys.first
|
63
|
+
member += "##{target_attribute_name}"
|
64
|
+
if target["attribute"][target_attribute_name]["cardinality"]
|
65
|
+
cardinality = target["attribute"][target_attribute_name]["cardinality"]
|
66
|
+
member += " [#{cardinality['min']}..#{cardinality['max']}]"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
else
|
70
|
+
sync_puts("member_type direct", 4)
|
71
|
+
end
|
72
|
+
sync_puts("member #{member}", 4)
|
73
|
+
|
74
|
+
sync_puts("}", 2)
|
75
|
+
end
|
76
|
+
sync_puts("diagram #{File.basename(ARGV[0], 'yml')[0..-2]} {")
|
77
|
+
sync_puts("title '#{view_yaml['title']}'", 2)
|
78
|
+
|
79
|
+
# Class associations notations
|
80
|
+
view_yaml["relations"]&.each do |values|
|
81
|
+
process_association(values["source"], values, encountered_relations)
|
82
|
+
end
|
83
|
+
|
84
|
+
view_yaml["imports"].keys.each do |entry|
|
85
|
+
import = YAML.safe_load(File.read(File.join(models_path, "#{entry}.yml")))
|
86
|
+
import_name = import["name"]
|
87
|
+
# Class notation
|
88
|
+
sync_puts("#{import['modelType']} #{import['name']} {", 2)
|
89
|
+
import["values"]&.each_pair do |key, values|
|
90
|
+
sync_puts("#{key}", 4)
|
91
|
+
end
|
92
|
+
import["attributes"]&.each_pair do |key, values|
|
93
|
+
cardinality = if values["cardinality"]
|
94
|
+
cardinality_val = values["cardinality"]
|
95
|
+
"[#{cardinality_val['min']}..#{cardinality_val['max']}]"
|
96
|
+
else
|
97
|
+
""
|
98
|
+
end
|
99
|
+
sync_puts("+#{key}: #{values['type']} #{cardinality}", 4)
|
100
|
+
end
|
101
|
+
sync_puts("}", 2)
|
102
|
+
|
103
|
+
# Associations notations
|
104
|
+
import["relations"]&.each do |values|
|
105
|
+
process_association(import_name, values, encountered_relations)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
sync_puts("}")
|
data/exe/lutaml-uml
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# encoding: UTF-8
|
3
|
+
# frozen_string_literal: true
|
3
4
|
|
4
5
|
# resolve bin path, ignoring symlinks
|
5
6
|
require "pathname"
|
@@ -15,6 +16,6 @@ class Gem::Specification
|
|
15
16
|
def this; self; end
|
16
17
|
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
require "lutaml/uml/interface/command_line"
|
20
|
+
|
21
|
+
Lutaml::Uml::Interface::CommandLine.run
|
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ruby-graphviz"
|
4
|
+
require "lutaml/layout/engine"
|
5
|
+
|
6
|
+
module Lutaml
|
7
|
+
module Layout
|
8
|
+
class GraphVizEngine < Engine
|
9
|
+
def render(type)
|
10
|
+
GraphViz
|
11
|
+
.parse_string(input)
|
12
|
+
.output(type => String)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/lutaml/uml.rb
CHANGED
data/lib/lutaml/uml/activity.rb
CHANGED
data/lib/lutaml/uml/actor.rb
CHANGED
@@ -1,17 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
##
|
2
4
|
## Behaviour metamodel
|
3
5
|
##
|
4
6
|
|
5
|
-
module Lutaml
|
6
|
-
|
7
|
-
class Actor < Classifier
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
7
|
+
module Lutaml
|
8
|
+
module Uml
|
9
|
+
class Actor < Classifier
|
10
|
+
def initialize
|
11
|
+
@name = nil
|
12
|
+
@xmi_id = nil
|
13
|
+
@stereotype = []
|
14
|
+
@generalization = []
|
15
|
+
@namespace = nil
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
15
19
|
end
|
16
|
-
|
17
|
-
end
|
@@ -1,15 +1,41 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lutaml
|
4
|
+
module Uml
|
5
|
+
class Association < TopElement
|
6
|
+
include HasMembers
|
7
|
+
|
8
|
+
attr_accessor :owner_end,
|
9
|
+
:owner_end_attribute_name,
|
10
|
+
:owner_end_cardinality,
|
11
|
+
:owner_end_type,
|
12
|
+
:member_end,
|
13
|
+
:member_end_attribute_name,
|
14
|
+
:member_end_cardinality,
|
15
|
+
:member_end_type,
|
16
|
+
:static,
|
17
|
+
:action
|
14
18
|
|
15
|
-
|
19
|
+
# TODO: move to Parslet::Transform
|
20
|
+
def members=(value)
|
21
|
+
value.group_by { |member| member.keys.first }
|
22
|
+
.each do |(type, group)|
|
23
|
+
if %w[owner_end member_end].include?(type)
|
24
|
+
group.each do |member|
|
25
|
+
member.each_pair do |key, member_value|
|
26
|
+
public_send("#{associtaion_type(key)}=", member_value)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
next
|
30
|
+
end
|
31
|
+
attribute_value = group.map(&:values).flatten
|
32
|
+
if attribute_value.length == 1 && !attribute_value.first.is_a?(Hash)
|
33
|
+
next public_send("#{associtaion_type(type)}=", attribute_value.first)
|
34
|
+
end
|
35
|
+
|
36
|
+
public_send("#{associtaion_type(type)}=", attribute_value)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/lutaml/uml/behavior.rb
CHANGED
data/lib/lutaml/uml/class.rb
CHANGED
@@ -1,17 +1,57 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "lutaml/uml/has_members"
|
4
|
+
require "lutaml/uml/classifier"
|
5
|
+
require "lutaml/uml/association"
|
6
|
+
require "lutaml/uml/top_element_attribute"
|
7
|
+
|
8
|
+
module Lutaml
|
9
|
+
module Uml
|
10
|
+
class Class < Classifier
|
11
|
+
include HasMembers
|
12
|
+
|
13
|
+
attr_accessor :nested_classifier,
|
14
|
+
:is_abstract,
|
15
|
+
:type
|
16
|
+
|
17
|
+
attr_reader :associations,
|
18
|
+
:attributes,
|
19
|
+
:members,
|
20
|
+
:modifier
|
21
|
+
|
22
|
+
def initialize(attributes = {})
|
23
|
+
@nested_classifier = []
|
24
|
+
@stereotype = []
|
25
|
+
@generalization = []
|
26
|
+
@is_abstract = false
|
27
|
+
super
|
28
|
+
end
|
16
29
|
|
17
|
-
|
30
|
+
def modifier=(value)
|
31
|
+
@modifier = value.to_s # TODO: Validate?
|
32
|
+
end
|
33
|
+
|
34
|
+
def attributes=(value)
|
35
|
+
@attributes = value.to_a.map do |attr|
|
36
|
+
TopElementAttribute.new(attr)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def associations=(value)
|
41
|
+
@associations = value.to_a.map do |attr|
|
42
|
+
Association.new(attr.to_h.merge(owner_end: name))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def methods
|
47
|
+
# @members&.select { |member| member.class == Method }
|
48
|
+
[]
|
49
|
+
end
|
50
|
+
|
51
|
+
def relationships
|
52
|
+
# @members&.select { |member| member.class == ClassRelationship }
|
53
|
+
[]
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|