rbuml 0.1.0
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 +7 -0
- data/bin/rbuml +9 -0
- data/lib/rbuml.rb +2 -0
- data/lib/rbuml/dot.rb +108 -0
- data/lib/rbuml/dsl.rb +65 -0
- data/lib/rbuml/models.rb +100 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1d197fadc0f325f5aaf69e7e1d466659b71ff64c
|
4
|
+
data.tar.gz: 6a3f847977a9e154ee3c4710f60bba15abb6f63a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6e6ea97d14e7425da642f6e6098268c44a9e8ce85d3f5b974ba525a692c2bc41a1a7599f0e43367c02d5c75ecc89abf46a39d29dee509745a0fbb9437bd94396
|
7
|
+
data.tar.gz: bce53d897766d8c201510cd528e44dcf47650a30d5a1543c08af89e20388e28304c461873d0471d201e4d04bab3070bc90c0cc3b52a25cd5f7346de7601fbb30
|
data/bin/rbuml
ADDED
data/lib/rbuml.rb
ADDED
data/lib/rbuml/dot.rb
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'graphviz'
|
2
|
+
|
3
|
+
require 'rbuml/models'
|
4
|
+
|
5
|
+
|
6
|
+
def rbuml_dot_render(classes, filename, format=:png)
|
7
|
+
g = GraphViz.new(:G, :type => :digraph, :ratio => :compress)
|
8
|
+
|
9
|
+
classes.each do |name, cls|
|
10
|
+
g.add_nodes(cls.name, :label => cls.dot_label, :shape => "record")
|
11
|
+
end
|
12
|
+
|
13
|
+
classes.each do |name, cls|
|
14
|
+
cls.notes.each_with_index do |note,i|
|
15
|
+
g.add_nodes("note#{cls.name}#{i}", :label => note.dot_label, :shape => :note)
|
16
|
+
g.add_edges(cls.name, "note#{cls.name}#{i}", :dir => :none)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
classes.each do |name, cls|
|
21
|
+
cls.interfaces.each do |inter|
|
22
|
+
g.add_edges(cls.name, inter, :arrowhead => :empty)
|
23
|
+
end
|
24
|
+
|
25
|
+
cls.parents.each do |parent|
|
26
|
+
g.add_edges(cls.name, parent, :arrowhead => :empty)
|
27
|
+
end
|
28
|
+
|
29
|
+
cls.relationships.each do |rel|
|
30
|
+
g.add_edges(cls.name, rel.kind, :label => rel.dot_label, :dir => :both, :arrowhead => :none, :arrowtail => :odiamond, :headlabel => rel.head_label)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
g.output(format => filename)
|
35
|
+
puts "saved " + filename
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class RbUMLClass
|
40
|
+
def dot_label
|
41
|
+
kind_lookup = {
|
42
|
+
:class => "",
|
43
|
+
:enumeration => "<<enumeration>>\n",
|
44
|
+
:interface => "<<interface>>\n",
|
45
|
+
}
|
46
|
+
attributes = @attributes.collect { |a| a.dot_label }.join('\l')
|
47
|
+
methods = @methods.collect { |m| m.dot_label }.join('\l')
|
48
|
+
"{#{kind_lookup[@kind]}#{@name}|#{attributes}\\l|#{methods}\\l}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
class RbUMLAttribute
|
54
|
+
def dot_label
|
55
|
+
visibility_lookup = {
|
56
|
+
:unspecified => '',
|
57
|
+
:public => '+',
|
58
|
+
:private => '-',
|
59
|
+
:protected => '#',
|
60
|
+
:derived => '/',
|
61
|
+
:package => '~',
|
62
|
+
}
|
63
|
+
kind = @kind ? " : #{@kind.to_s}" : ""
|
64
|
+
"#{visibility_lookup[@visibility]}#{@name}#{kind}"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
class RbUMLRelationship
|
70
|
+
def dot_label
|
71
|
+
@verb ? "<<#{@verb}>>" : ''
|
72
|
+
end
|
73
|
+
|
74
|
+
def head_label
|
75
|
+
@multiplicity ? @multiplicity : ''
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
class RbUMLMethod
|
81
|
+
def dot_label
|
82
|
+
visibility_lookup = {
|
83
|
+
:unspecified => '',
|
84
|
+
:public => '+',
|
85
|
+
:private => '-',
|
86
|
+
:protected => '#',
|
87
|
+
:derived => '/',
|
88
|
+
:package => '~',
|
89
|
+
}
|
90
|
+
args = @arguments.collect { |p| p.dot_label }.join(', ')
|
91
|
+
kind = @returns ? " : #{@returns}" : ""
|
92
|
+
"#{visibility_lookup[@visibility]}#{@name}(#{args})#{kind}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
class RbUMLMethodArgument
|
98
|
+
def dot_label
|
99
|
+
@kind ? "#{@name} : #{@kind}" : "#{@name}"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
|
104
|
+
class RbUMLNote
|
105
|
+
def dot_label
|
106
|
+
@text.split("\n").collect {|line| line.gsub("\t", '') }.join('\l') + '\l'
|
107
|
+
end
|
108
|
+
end
|
data/lib/rbuml/dsl.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'rbuml/models'
|
2
|
+
require 'rbuml/dot'
|
3
|
+
|
4
|
+
$known_classes = {}
|
5
|
+
$current = nil
|
6
|
+
$method = nil
|
7
|
+
|
8
|
+
def uml_class(*params, &block)
|
9
|
+
$current = RbUMLClass.new(*params)
|
10
|
+
if block_given?
|
11
|
+
block.call $current
|
12
|
+
end
|
13
|
+
$known_classes[$current.name] = $current
|
14
|
+
$current = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
def kind(k)
|
19
|
+
$current.kind = k
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def note(text)
|
24
|
+
$current.add_note RbUMLNote.new(text)
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def extends(kind)
|
29
|
+
$current.add_parent kind
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def implements(kind)
|
34
|
+
$current.add_interface kind
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def attribute(*params)
|
39
|
+
$current.add_attribute RbUMLAttribute.new(*params)
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
def relationship(*params)
|
44
|
+
$current.add_relationship RbUMLRelationship.new(*params)
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
def method(*params, &block)
|
49
|
+
$method = RbUMLMethod.new(*params)
|
50
|
+
if block_given?
|
51
|
+
block.call $method
|
52
|
+
end
|
53
|
+
$current.add_method $method
|
54
|
+
$method = nil
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
def argument(*params)
|
59
|
+
$method.add_argument RbUMLMethodArgument.new(*params)
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
def save(filename, format=:png)
|
64
|
+
rbuml_dot_render $known_classes, filename, format
|
65
|
+
end
|
data/lib/rbuml/models.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
class RbUMLClass
|
2
|
+
attr_reader :name
|
3
|
+
attr_reader :parents
|
4
|
+
attr_reader :interfaces
|
5
|
+
attr_reader :relationships
|
6
|
+
attr_reader :notes
|
7
|
+
attr_writer :kind
|
8
|
+
|
9
|
+
def initialize(name, kind=:class)
|
10
|
+
@name = name
|
11
|
+
@parents = []
|
12
|
+
@interfaces = []
|
13
|
+
@attributes = []
|
14
|
+
@relationships = []
|
15
|
+
@methods = []
|
16
|
+
@notes = []
|
17
|
+
@kind = kind
|
18
|
+
end
|
19
|
+
|
20
|
+
def add_parent(cls)
|
21
|
+
@parents << cls
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_interface(inter)
|
25
|
+
@interfaces << inter
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_attribute(attrib)
|
29
|
+
@attributes << attrib
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_relationship(rel)
|
33
|
+
@relationships << rel
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_method(method)
|
37
|
+
@methods << method
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_note(note)
|
41
|
+
@notes << note
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
class RbUMLAttribute
|
47
|
+
attr_reader :kind
|
48
|
+
|
49
|
+
def initialize(name, kind, visibility=:unspecified)
|
50
|
+
@name = name
|
51
|
+
@kind = kind
|
52
|
+
@visibility = visibility
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
class RbUMLRelationship
|
58
|
+
attr_reader :kind
|
59
|
+
|
60
|
+
def initialize(kind, verb=nil, multiplicity=nil)
|
61
|
+
@kind = kind
|
62
|
+
@verb = verb
|
63
|
+
@multiplicity = multiplicity
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
class RbUMLMethod
|
69
|
+
attr_reader :name
|
70
|
+
attr_reader :note
|
71
|
+
|
72
|
+
def initialize(name, returns=nil, visibility=:unspecified)
|
73
|
+
@name = name
|
74
|
+
@returns = returns
|
75
|
+
@arguments = []
|
76
|
+
@visibility = visibility
|
77
|
+
end
|
78
|
+
|
79
|
+
def add_argument(arg)
|
80
|
+
@arguments << arg
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
class RbUMLMethodArgument
|
86
|
+
attr_reader :name
|
87
|
+
attr_reader :kind
|
88
|
+
|
89
|
+
def initialize(name, kind=nil)
|
90
|
+
@name = name
|
91
|
+
@kind = kind
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
|
96
|
+
class RbUMLNote
|
97
|
+
def initialize(text)
|
98
|
+
@text = text
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rbuml
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Neil Isaac
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-graphviz
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.2'
|
27
|
+
description: rbuml provides classes and a dsl for representing uml class relationships
|
28
|
+
that can be rendered as a uml class diagram using graphviz dot
|
29
|
+
email: mail@neilisaac.ca
|
30
|
+
executables:
|
31
|
+
- rbuml
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/rbuml
|
36
|
+
- lib/rbuml.rb
|
37
|
+
- lib/rbuml/dot.rb
|
38
|
+
- lib/rbuml/dsl.rb
|
39
|
+
- lib/rbuml/models.rb
|
40
|
+
homepage: https://github.com/neilisaac/rbuml
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata: {}
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
requirements: []
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 2.2.2
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: rbuml is a uml dsl for ruby for generating class diagrams
|
64
|
+
test_files: []
|