diaspora-cluster-creator 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -24,6 +24,7 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency 'growl'
25
25
  gem.add_development_dependency 'debugger'
26
26
  gem.add_development_dependency 'aruba'
27
+ gem.add_development_dependency 'factory_girl'
27
28
 
28
29
  gem.add_runtime_dependency "ruby-graphviz"
29
30
  gem.add_runtime_dependency "main"
@@ -19,6 +19,9 @@ Scenario: Specify with names
19
19
  Then it should pass with:
20
20
  """
21
21
  graph Cluster {
22
+ "Cluster Legend" [label = "T - Technology
23
+ R - Resources
24
+ E - Environment", shape = "box"];
22
25
  Sparta [label = "Sparta
23
26
  T2 R0 E-1"];
24
27
  Athens [label = "Athens
@@ -32,6 +35,9 @@ Scenario: Specify with technology guarantee
32
35
  Then it should pass with output like:
33
36
  """
34
37
  graph Cluster {
38
+ "Cluster Legend" \[label = "T - Technology
39
+ R - Resources
40
+ E - Environment", shape = "box"\];
35
41
  Sparta \[label = "Sparta
36
42
  T2 R0 E-1"\];
37
43
  Athens \[label = "Athens
@@ -79,6 +85,9 @@ Scenario: Specify different attributes
79
85
  Then it should pass with output like:
80
86
  """
81
87
  graph Cluster {
88
+ "Cluster Legend" \[label = "M - Magic
89
+ R - Religion
90
+ S - Science", shape = "box"\];
82
91
  A \[label = "A
83
92
  M-?\d R-?\d S-?\d"\];
84
93
  B \[label = "B
@@ -115,6 +124,19 @@ Scenario: Specify different attributes with prefix override
115
124
  C -- D
116
125
  D -- E
117
126
  """
127
+
128
+ @wip
129
+ Scenario: Specify different attributes with guarantee
130
+ When I run `diaspora-cluster attributes="Knights,Dragons,Maidens" guarantee="2 Knights @ 2 and 2 Dragons @ -3" names="Sparta {K1},Athens {K1}"`
131
+ Then it should pass with output like:
132
+ """
133
+ graph Cluster {
134
+ Sparta \[label = "Sparta
135
+ K2 D-3 M-?\d"\];
136
+ Athens \[label = "Athens
137
+ K2 D-3 M-?\d"\];
138
+ Sparta -- Athens
139
+ """
118
140
 
119
141
  Scenario: Specify different attributes with default
120
142
  When I run `diaspora-cluster names="Sparta{M5},Athens{R-5}" attributes="Magic, Religion, Science"`
@@ -0,0 +1,8 @@
1
+ module Diaspora
2
+ module Cluster
3
+ module Creator
4
+ module Conversions
5
+ end
6
+ end
7
+ end
8
+ end
@@ -1,7 +1,7 @@
1
1
  module Diaspora
2
2
  module Cluster
3
3
  module Creator
4
- class EdgeDrawer
4
+ class EdgeCollectionFactory
5
5
  extend DependencyInjector
6
6
  def_injector(:dice) { FateDice.new }
7
7
  attr_reader :cluster
@@ -9,7 +9,7 @@ module Diaspora
9
9
  @cluster = cluster
10
10
  end
11
11
 
12
- def draw(nodes)
12
+ def build_from(nodes)
13
13
  return @edges if @edges
14
14
  nodes.each_with_index do |node, i|
15
15
  result = dice.roll
@@ -3,6 +3,9 @@ require 'set'
3
3
  require_relative 'fate_dice'
4
4
  require_relative 'node_attribute'
5
5
 
6
+ # TODO: Need to write NodeAttribute collection class; the frequent
7
+ # use of attributes.detect smells bad.
8
+
6
9
  module Diaspora
7
10
  module Cluster
8
11
  module Creator
@@ -2,11 +2,37 @@ require 'graphviz'
2
2
  module Diaspora
3
3
  module Cluster
4
4
  module Creator
5
+ module Conversions
6
+ module Legend
7
+ def to_legend
8
+ if respond_to?(:prefix)
9
+ "#{prefix} - #{to_s}"
10
+ else
11
+ to_s
12
+ end
13
+ end
14
+ end
15
+ private
16
+ def Legendary(item)
17
+ return item if item.kind_of?(Legend)
18
+ if item.is_a?(Array)
19
+ item.each {|i| i.extend(Legend) }
20
+ def item.to_legend
21
+ collect(&:to_legend).join("\n")
22
+ end
23
+ else
24
+ item.extend(Legend)
25
+ end
26
+ item
27
+ end
28
+ end
5
29
  class Template
30
+ include Conversions
6
31
  attr_reader :cluster
7
32
  def initialize(cluster)
8
33
  raise RuntimeError unless cluster.respond_to?(:each_node)
9
34
  raise RuntimeError unless cluster.respond_to?(:each_edge)
35
+ raise RuntimeError unless cluster.respond_to?(:attributes)
10
36
  @cluster = cluster
11
37
  end
12
38
 
@@ -26,6 +52,8 @@ module Diaspora
26
52
  def canvas
27
53
  return @canvas if @canvas
28
54
  @canvas = GraphViz.new(cluster.to_s, :type => :graph )
55
+
56
+ @canvas.add_nodes('Cluster Legend', :label => Legendary(cluster.attributes).to_legend, :shape => 'box')
29
57
 
30
58
  cluster.each_node do |node|
31
59
  options = {}
@@ -1,7 +1,7 @@
1
1
  module Diaspora
2
2
  module Cluster
3
3
  module Creator
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
6
6
  end
7
7
  end
@@ -1,15 +1,15 @@
1
1
  require_relative '../spec_helper_lite'
2
- require 'edge_drawer'
2
+ require 'edge_collection_factory'
3
3
 
4
- describe EdgeDrawer do
5
- subject { EdgeDrawer.new(context)}
4
+ describe EdgeCollectionFactory do
5
+ subject { EdgeCollectionFactory.new(context)}
6
6
  let(:context) { Object.new }
7
7
 
8
- describe '#draw' do
8
+ describe '#build_from' do
9
9
  it 'should return' do
10
10
  nodes = ['a','b','c']
11
11
  with_loaded_dice(0,subject) do
12
- output = subject.draw(nodes)
12
+ output = subject.build_from(nodes)
13
13
 
14
14
  output.must_include ['a','b']
15
15
  output.must_include ['a','c']
@@ -3,14 +3,6 @@ require 'node'
3
3
  require 'ostruct'
4
4
 
5
5
  describe Node do
6
- class MockAttribute
7
- attr_accessor :value, :to_sym, :prefix
8
- def to_i; value; end
9
- def value
10
- @value.to_i
11
- end
12
- end
13
-
14
6
  let(:attribute_builder) { lambda {|node,attribute| attribute } }
15
7
  let(:name) { 'Name' }
16
8
  subject {
@@ -22,9 +14,9 @@ describe Node do
22
14
  Object.new.tap do |obj|
23
15
  def obj.attributes
24
16
  [
25
- MockAttribute.new.tap{|obj| obj.to_sym = :technology; obj.prefix = 'T'; obj.value = 1},
26
- MockAttribute.new.tap{|obj| obj.to_sym = :resources; obj.prefix = 'R'; obj.value = 1},
27
- MockAttribute.new.tap{|obj| obj.to_sym = :environment; obj.prefix = 'E'; obj.value = 1},
17
+ FactoryGirl.build(:attribute, :to_sym => :technology, :value => 1, :prefix => 'T'),
18
+ FactoryGirl.build(:attribute, :to_sym => :resources, :value => 1, :prefix => 'R'),
19
+ FactoryGirl.build(:attribute, :to_sym => :environment, :value => 1, :prefix => 'E'),
28
20
  ]
29
21
  end
30
22
  end
@@ -34,9 +26,9 @@ describe Node do
34
26
  Object.new.tap do |obj|
35
27
  def obj.attributes
36
28
  [
37
- MockAttribute.new.tap{|obj| obj.to_sym = :knights; obj.prefix = 'K'; obj.value = 1},
38
- MockAttribute.new.tap{|obj| obj.to_sym = :dragons; obj.prefix = 'D'; obj.value = 2},
39
- MockAttribute.new.tap{|obj| obj.to_sym = :maidens; obj.prefix = 'M'; obj.value = 3},
29
+ FactoryGirl.build(:attribute, :to_sym => :knights, :prefix => 'K', :value => 1),
30
+ FactoryGirl.build(:attribute, :to_sym => :dragons, :prefix => 'D', :value => 2),
31
+ FactoryGirl.build(:attribute, :to_sym => :maidens, :prefix => 'M', :value => 3),
40
32
  ]
41
33
  end
42
34
  end
@@ -1,10 +1,16 @@
1
1
  require_relative '../spec_helper_lite'
2
2
  require 'template'
3
+ require 'ostruct'
3
4
 
4
5
  describe Template do
5
6
  subject { Template.new(graph) }
6
7
  let(:graph) {
7
8
  object = Object.new
9
+ def object.attributes
10
+ [
11
+ FactoryGirl.build(:attribute, :name => 'Name')
12
+ ]
13
+ end
8
14
  def object.each_node
9
15
  yield('a')
10
16
  yield('b')
@@ -23,6 +29,7 @@ describe Template do
23
29
  subject.to_s.must_equal(
24
30
  [
25
31
  %(graph #{graph.to_s.inspect} {),
32
+ %( "Cluster Legend" [label = "N - Name", shape = "box"];),
26
33
  %( a [label = "a"];),
27
34
  %( b [label = "b"];),
28
35
  %( c [label = "c"];),
@@ -33,4 +40,21 @@ describe Template do
33
40
  )
34
41
  end
35
42
  end
43
+
44
+ describe 'Conversions' do
45
+ describe 'Legendary' do
46
+ it 'should append to_legend method' do
47
+ object = FactoryGirl.build(:attribute, :to_s => 'Shoe', :prefix => 'S')
48
+ self.extend(Conversions)
49
+ Legendary(object).to_legend.must_equal('S - Shoe')
50
+ end
51
+
52
+ it 'should append to_legend method' do
53
+ object1 = FactoryGirl.build(:attribute, :to_s => 'Shoe', :prefix => 'S')
54
+ object2 = FactoryGirl.build(:attribute, :to_s => 'Hair', :prefix => 'H')
55
+ self.extend(Conversions)
56
+ Legendary([object1,object2]).to_legend.must_equal("S - Shoe\nH - Hair")
57
+ end
58
+ end
59
+ end
36
60
  end
@@ -0,0 +1,31 @@
1
+ class AttributeInterface
2
+ attr_accessor :name
3
+ attr_writer :value, :prefix, :to_sym, :to_s, :to_i
4
+
5
+ def to_sym
6
+ @to_sym || name.gsub(/\W+/,'_').downcase.to_sym
7
+ end
8
+ def prefix
9
+ @prefix || name.slice(0)
10
+ end
11
+
12
+ def to_s
13
+ @to_s || name.to_s
14
+ end
15
+
16
+ def to_i
17
+ @to_i || @value.to_i
18
+ end
19
+
20
+ def value
21
+ (@value || 0).to_i
22
+ end
23
+ end
24
+ FactoryGirl.define do
25
+ sequence(:name) do |n|
26
+ "name_#{n}"
27
+ end
28
+ factory(:attribute, :class => AttributeInterface) do
29
+ name { FactoryGirl.generate(:name) }
30
+ end
31
+ end
@@ -2,8 +2,10 @@ gem 'minitest' # demand gem version
2
2
  require 'minitest/spec'
3
3
  require 'minitest/autorun'
4
4
  require 'ostruct'
5
+ require 'factory_girl'
5
6
  $: << File.expand_path('../lib/diaspora-cluster-creator', File.dirname(__FILE__))
6
7
  require 'diaspora-cluster-creator'
8
+ require_relative 'factories'
7
9
 
8
10
  # Cheating a bit to help tests be a bit more readable
9
11
  include Diaspora::Cluster::Creator
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diaspora-cluster-creator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-04-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: cucumber
16
- requirement: &2151894880 !ruby/object:Gem::Requirement
16
+ requirement: &2152626040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *2151894880
24
+ version_requirements: *2152626040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bundler
27
- requirement: &2151894400 !ruby/object:Gem::Requirement
27
+ requirement: &2152625020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2151894400
35
+ version_requirements: *2152625020
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &2151893780 !ruby/object:Gem::Requirement
38
+ requirement: &2152624240 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2151893780
46
+ version_requirements: *2152624240
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: guard
49
- requirement: &2151893300 !ruby/object:Gem::Requirement
49
+ requirement: &2152623500 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2151893300
57
+ version_requirements: *2152623500
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: guard-minitest
60
- requirement: &2151892780 !ruby/object:Gem::Requirement
60
+ requirement: &2152622660 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2151892780
68
+ version_requirements: *2152622660
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: guard-bundler
71
- requirement: &2151892140 !ruby/object:Gem::Requirement
71
+ requirement: &2152621640 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2151892140
79
+ version_requirements: *2152621640
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: guard-cucumber
82
- requirement: &2151891540 !ruby/object:Gem::Requirement
82
+ requirement: &2152620600 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *2151891540
90
+ version_requirements: *2152620600
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: growl
93
- requirement: &2151891000 !ruby/object:Gem::Requirement
93
+ requirement: &2152619660 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: '0'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *2151891000
101
+ version_requirements: *2152619660
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: debugger
104
- requirement: &2151890480 !ruby/object:Gem::Requirement
104
+ requirement: &2152618940 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - ! '>='
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: '0'
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *2151890480
112
+ version_requirements: *2152618940
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: aruba
115
- requirement: &2151889940 !ruby/object:Gem::Requirement
115
+ requirement: &2152618440 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - ! '>='
@@ -120,10 +120,21 @@ dependencies:
120
120
  version: '0'
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *2151889940
123
+ version_requirements: *2152618440
124
+ - !ruby/object:Gem::Dependency
125
+ name: factory_girl
126
+ requirement: &2152617900 !ruby/object:Gem::Requirement
127
+ none: false
128
+ requirements:
129
+ - - ! '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: *2152617900
124
135
  - !ruby/object:Gem::Dependency
125
136
  name: ruby-graphviz
126
- requirement: &2151889460 !ruby/object:Gem::Requirement
137
+ requirement: &2152617280 !ruby/object:Gem::Requirement
127
138
  none: false
128
139
  requirements:
129
140
  - - ! '>='
@@ -131,10 +142,10 @@ dependencies:
131
142
  version: '0'
132
143
  type: :runtime
133
144
  prerelease: false
134
- version_requirements: *2151889460
145
+ version_requirements: *2152617280
135
146
  - !ruby/object:Gem::Dependency
136
147
  name: main
137
- requirement: &2151888940 !ruby/object:Gem::Requirement
148
+ requirement: &2152616440 !ruby/object:Gem::Requirement
138
149
  none: false
139
150
  requirements:
140
151
  - - ! '>='
@@ -142,10 +153,10 @@ dependencies:
142
153
  version: '0'
143
154
  type: :runtime
144
155
  prerelease: false
145
- version_requirements: *2151888940
156
+ version_requirements: *2152616440
146
157
  - !ruby/object:Gem::Dependency
147
158
  name: dependency_injector
148
- requirement: &2151888460 !ruby/object:Gem::Requirement
159
+ requirement: &2152615640 !ruby/object:Gem::Requirement
149
160
  none: false
150
161
  requirements:
151
162
  - - ! '>='
@@ -153,7 +164,7 @@ dependencies:
153
164
  version: '0'
154
165
  type: :runtime
155
166
  prerelease: false
156
- version_requirements: *2151888460
167
+ version_requirements: *2152615640
157
168
  description: Command-line utility to create Diaspora cluster
158
169
  email:
159
170
  - jeremy.n.friesen@gmail.com
@@ -169,7 +180,6 @@ files:
169
180
  - LICENSE
170
181
  - README.md
171
182
  - Rakefile
172
- - TODO.todo
173
183
  - bin/diaspora-cluster
174
184
  - diaspora-cluster-creator.gemspec
175
185
  - features/cluster.feature
@@ -189,7 +199,8 @@ files:
189
199
  - lib/diaspora-cluster-creator/attribute.rb
190
200
  - lib/diaspora-cluster-creator/attribute_collection_factory.rb
191
201
  - lib/diaspora-cluster-creator/cluster.rb
192
- - lib/diaspora-cluster-creator/edge_drawer.rb
202
+ - lib/diaspora-cluster-creator/conversions.rb
203
+ - lib/diaspora-cluster-creator/edge_collection_factory.rb
193
204
  - lib/diaspora-cluster-creator/fate_dice.rb
194
205
  - lib/diaspora-cluster-creator/guarantor.rb
195
206
  - lib/diaspora-cluster-creator/node.rb
@@ -200,7 +211,7 @@ files:
200
211
  - spec/diaspora-cluster-creator/attribute_collection_factory_spec.rb
201
212
  - spec/diaspora-cluster-creator/attribute_spec.rb
202
213
  - spec/diaspora-cluster-creator/cluster_spec.rb
203
- - spec/diaspora-cluster-creator/edge_drawer_spec.rb
214
+ - spec/diaspora-cluster-creator/edge_collection_factory_spec.rb
204
215
  - spec/diaspora-cluster-creator/fate_dice_spec.rb
205
216
  - spec/diaspora-cluster-creator/guarantor_spec.rb
206
217
  - spec/diaspora-cluster-creator/node_attribute_spec.rb
@@ -208,6 +219,7 @@ files:
208
219
  - spec/diaspora-cluster-creator/node_spec.rb
209
220
  - spec/diaspora-cluster-creator/template_integration_spec.rb
210
221
  - spec/diaspora-cluster-creator/template_spec.rb
222
+ - spec/factories.rb
211
223
  - spec/spec_helper_lite.rb
212
224
  homepage: ''
213
225
  licenses: []
@@ -250,7 +262,7 @@ test_files:
250
262
  - spec/diaspora-cluster-creator/attribute_collection_factory_spec.rb
251
263
  - spec/diaspora-cluster-creator/attribute_spec.rb
252
264
  - spec/diaspora-cluster-creator/cluster_spec.rb
253
- - spec/diaspora-cluster-creator/edge_drawer_spec.rb
265
+ - spec/diaspora-cluster-creator/edge_collection_factory_spec.rb
254
266
  - spec/diaspora-cluster-creator/fate_dice_spec.rb
255
267
  - spec/diaspora-cluster-creator/guarantor_spec.rb
256
268
  - spec/diaspora-cluster-creator/node_attribute_spec.rb
@@ -258,4 +270,5 @@ test_files:
258
270
  - spec/diaspora-cluster-creator/node_spec.rb
259
271
  - spec/diaspora-cluster-creator/template_integration_spec.rb
260
272
  - spec/diaspora-cluster-creator/template_spec.rb
273
+ - spec/factories.rb
261
274
  - spec/spec_helper_lite.rb
data/TODO.todo DELETED
@@ -1,2 +0,0 @@
1
- – Allow different attributes to be passed.
2
- – The above implies an NodeAttribute class; And a Config class as well.