yuml 0.4.0 → 0.4.1
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 +4 -4
- data/README.md +13 -3
- data/lib/yuml.rb +4 -5
- data/lib/yuml/class.rb +22 -15
- data/lib/yuml/note.rb +2 -3
- data/spec/yuml_class_spec.rb +22 -6
- data/spec/yuml_note_spec.rb +1 -1
- data/spec/yuml_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08d748325a616407967febe42befb19be51ca4b6
|
4
|
+
data.tar.gz: 3366bcee2cb3dd6009a426a4e5114859ecaa5003
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b7720f885df0dd8fe38d71223c7c8e221d30fc867435fde0e8554cba425413e5790dd8abd5d2c04f8d99c2930dbe1d996cfbba85926378ea0ee8fc75f3de7cd5
|
7
|
+
data.tar.gz: 11ff15392add8a1c50919e6badddd4bedc8996573958cd12e55c383b04d52430c0c592c25c29f16c717c488e35905b11f5345e648fd650c847e231604e8a7ddb
|
data/README.md
CHANGED
@@ -16,9 +16,12 @@ end
|
|
16
16
|
|
17
17
|
To generate a class for the document use `uml.class` and pass a code block in to configure it. It accepts the following methods for configuration.
|
18
18
|
|
19
|
-
* name (required)
|
20
|
-
*
|
21
|
-
*
|
19
|
+
* `name(name = nil)` (required)
|
20
|
+
* `interface(interface = nil, sterotype = 'interface')`*
|
21
|
+
* `variables(*args)`
|
22
|
+
* `methods(*args)`
|
23
|
+
|
24
|
+
\*use `interface` in place of `name` when generating an interface
|
22
25
|
|
23
26
|
#### Example
|
24
27
|
|
@@ -34,6 +37,13 @@ document = uml.class do
|
|
34
37
|
end
|
35
38
|
```
|
36
39
|
|
40
|
+
```ruby
|
41
|
+
shape = uml.class do
|
42
|
+
interface 'Shape', 'module'
|
43
|
+
methods '+draw(id: int, content: String, style: Symbol)'
|
44
|
+
end
|
45
|
+
```
|
46
|
+
|
37
47
|
### Adding Relationships
|
38
48
|
|
39
49
|
After generating some classes to add relationships to them use the following `YUML::Class` methods.
|
data/lib/yuml.rb
CHANGED
@@ -17,12 +17,11 @@ module YUML
|
|
17
17
|
'#' => "\u0023"
|
18
18
|
}
|
19
19
|
|
20
|
-
def generate(
|
21
|
-
options = { file: '/tmp/yuml.pdf' }.merge(options)
|
20
|
+
def generate(file: '/tmp/yuml.pdf')
|
22
21
|
classes.clear
|
23
22
|
notes.clear
|
24
23
|
yield self
|
25
|
-
fetch_uml
|
24
|
+
fetch_uml file
|
26
25
|
end
|
27
26
|
|
28
27
|
def class(&block)
|
@@ -32,8 +31,8 @@ module YUML
|
|
32
31
|
yuml_class
|
33
32
|
end
|
34
33
|
|
35
|
-
def attach_note(content,
|
36
|
-
notes << YUML::Note.create(content,
|
34
|
+
def attach_note(content, color = nil)
|
35
|
+
notes << YUML::Note.create(content, color)
|
37
36
|
end
|
38
37
|
|
39
38
|
private
|
data/lib/yuml/class.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module YUML
|
2
2
|
# Represents a yUML Class
|
3
3
|
class Class
|
4
|
-
attr_writer :name
|
4
|
+
attr_writer :name
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@methods = []
|
@@ -14,11 +14,18 @@ module YUML
|
|
14
14
|
"#{normalized_interface}#{@name}"
|
15
15
|
end
|
16
16
|
|
17
|
-
def interface(interface = nil)
|
17
|
+
def interface(interface = nil, sterotype = 'interface')
|
18
18
|
@interface = interface if interface
|
19
|
+
@sterotype = sterotype if interface
|
19
20
|
@interface
|
20
21
|
end
|
21
22
|
|
23
|
+
def interface=(*args)
|
24
|
+
args.flatten!
|
25
|
+
@interface = args.first
|
26
|
+
@sterotype = args.size > 1 ? args.pop : 'interface'
|
27
|
+
end
|
28
|
+
|
22
29
|
def variables(*args)
|
23
30
|
args.flatten!
|
24
31
|
return attributes(@variables) if args.empty?
|
@@ -31,28 +38,28 @@ module YUML
|
|
31
38
|
@methods << normalize(args)
|
32
39
|
end
|
33
40
|
|
34
|
-
def has_a(dest,
|
35
|
-
|
36
|
-
relationship = YUML::Relationship.send(
|
41
|
+
def has_a(dest, type: :aggregation, cardinality: nil)
|
42
|
+
type = :aggregation unless %i(composition aggregation).include?(type)
|
43
|
+
relationship = YUML::Relationship.send(type, cardinality)
|
37
44
|
@relationships << "[#{name}]#{relationship}[#{dest.name}]"
|
38
45
|
end
|
39
46
|
|
40
|
-
def is_a(dest,
|
41
|
-
|
42
|
-
relationship = YUML::Relationship.send(
|
47
|
+
def is_a(dest, type: :inheritance)
|
48
|
+
type = :inheritance unless %i(inheritance interface).include?(type)
|
49
|
+
relationship = YUML::Relationship.send(type)
|
43
50
|
@relationships << "[#{dest.name}]#{relationship}[#{name}]"
|
44
51
|
end
|
45
52
|
|
46
|
-
def associated_with(dest,
|
47
|
-
|
53
|
+
def associated_with(dest, type: :directed_assoication, cardinality: nil)
|
54
|
+
type = :directed_assoication unless %i(
|
48
55
|
association directed_assoication two_way_association dependency
|
49
|
-
).include?(
|
50
|
-
relationship = YUML::Relationship.send(
|
56
|
+
).include?(type)
|
57
|
+
relationship = YUML::Relationship.send(type, cardinality)
|
51
58
|
@relationships << "[#{name}]#{relationship}[#{dest.name}]"
|
52
59
|
end
|
53
60
|
|
54
|
-
def attach_note(content,
|
55
|
-
@relationships << "[#{name}]-#{YUML::Note.create(content,
|
61
|
+
def attach_note(content, color = nil)
|
62
|
+
@relationships << "[#{name}]-#{YUML::Note.create(content, color)}"
|
56
63
|
end
|
57
64
|
|
58
65
|
def to_s
|
@@ -74,7 +81,7 @@ module YUML
|
|
74
81
|
|
75
82
|
def normalized_interface
|
76
83
|
name interface unless @name
|
77
|
-
return normalize([
|
84
|
+
return normalize(["<<#{@sterotype}>>"]).first << ';' if interface
|
78
85
|
end
|
79
86
|
|
80
87
|
def attributes(attrs)
|
data/lib/yuml/note.rb
CHANGED
data/spec/yuml_class_spec.rb
CHANGED
@@ -42,15 +42,31 @@ describe YUML::Class do
|
|
42
42
|
left = "#{YUML::ESCAPE_CHARACTERS['<']}" * 2
|
43
43
|
right = "#{YUML::ESCAPE_CHARACTERS['>']}" * 2
|
44
44
|
@interface_uml = "[#{left}interface#{right};Document]"
|
45
|
+
@module_uml = "[#{left}module#{right};Document]"
|
45
46
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
|
48
|
+
context 'with default sterotype' do
|
49
|
+
it 'takes an interface and updates the class' do
|
50
|
+
@uut.interface 'Document'
|
51
|
+
expect(@uut.to_s).to eq @interface_uml
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should work with interface=' do
|
55
|
+
@uut.interface = 'Document'
|
56
|
+
expect(@uut.to_s).to eq @interface_uml
|
57
|
+
end
|
49
58
|
end
|
50
59
|
|
51
|
-
|
52
|
-
|
53
|
-
|
60
|
+
context 'with custom sterotype' do
|
61
|
+
it 'takes an interface and updates the class' do
|
62
|
+
@uut.interface 'Document', 'module'
|
63
|
+
expect(@uut.to_s).to eq @module_uml
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'should work with interface=' do
|
67
|
+
@uut.interface = 'Document', 'module'
|
68
|
+
expect(@uut.to_s).to eq @module_uml
|
69
|
+
end
|
54
70
|
end
|
55
71
|
end
|
56
72
|
|
data/spec/yuml_note_spec.rb
CHANGED
@@ -4,7 +4,7 @@ require_relative '../lib/yuml'
|
|
4
4
|
describe YUML::Note do
|
5
5
|
describe '#create' do
|
6
6
|
it 'should return a formatted string' do
|
7
|
-
note = YUML::Note.create('This diagram blongs to Derek Stride',
|
7
|
+
note = YUML::Note.create('This diagram blongs to Derek Stride', :green)
|
8
8
|
expect(note).to eq '[note: This diagram blongs to Derek Stride{bg:green}]'
|
9
9
|
end
|
10
10
|
end
|
data/spec/yuml_spec.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yuml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Derek Stride
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|