diaspora-cluster-creator 0.2.0 → 0.3.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.
- data/.gitignore +1 -2
- data/Guardfile +1 -2
- data/README.md +2 -0
- data/TODO.todo +2 -0
- data/bin/diaspora-cluster +11 -8
- data/diaspora-cluster-creator.gemspec +2 -0
- data/features/cluster.feature +1 -1
- data/features/command_line.feature +165 -0
- data/features/node.feature +13 -0
- data/features/step_definitions/cluster_steps.rb +3 -3
- data/features/step_definitions/command_line_steps.rb +7 -0
- data/features/step_definitions/node_steps.rb +16 -0
- data/features/support/aruba.rb +1 -0
- data/features/support/world.rb +4 -8
- data/lib/diaspora-cluster-creator.rb +12 -9
- data/lib/diaspora-cluster-creator/attribute.rb +29 -0
- data/lib/diaspora-cluster-creator/attribute_collection_factory.rb +29 -0
- data/lib/diaspora-cluster-creator/cluster.rb +31 -18
- data/lib/diaspora-cluster-creator/edge_drawer.rb +41 -0
- data/lib/diaspora-cluster-creator/guarantor.rb +21 -0
- data/lib/diaspora-cluster-creator/node.rb +71 -0
- data/lib/diaspora-cluster-creator/node_attribute.rb +41 -0
- data/lib/diaspora-cluster-creator/node_collection_factory.rb +30 -0
- data/lib/diaspora-cluster-creator/template.rb +23 -16
- data/lib/diaspora-cluster-creator/version.rb +1 -1
- data/spec/diaspora-cluster-creator/attribute_collection_factory_spec.rb +31 -0
- data/spec/diaspora-cluster-creator/attribute_spec.rb +69 -0
- data/spec/diaspora-cluster-creator/cluster_spec.rb +66 -15
- data/spec/diaspora-cluster-creator/edge_drawer_spec.rb +21 -0
- data/spec/diaspora-cluster-creator/guarantor_spec.rb +54 -0
- data/spec/diaspora-cluster-creator/node_attribute_spec.rb +36 -0
- data/spec/diaspora-cluster-creator/node_collection_factory_spec.rb +27 -0
- data/spec/diaspora-cluster-creator/node_spec.rb +65 -0
- data/spec/diaspora-cluster-creator/template_integration_spec.rb +9 -10
- data/spec/diaspora-cluster-creator/template_spec.rb +9 -2
- metadata +78 -34
- data/features/star_system.feature +0 -13
- data/features/step_definitions/star_system_steps.rb +0 -16
- data/lib/diaspora-cluster-creator/graph.rb +0 -58
- data/lib/diaspora-cluster-creator/star_system.rb +0 -80
- data/spec/diaspora-cluster-creator/graph_spec.rb +0 -34
- data/spec/diaspora-cluster-creator/star_system_spec.rb +0 -103
@@ -1,13 +0,0 @@
|
|
1
|
-
Feature: Star System Creation
|
2
|
-
|
3
|
-
Scenario: Star System Creation
|
4
|
-
When I create a Star System
|
5
|
-
Then it should have a technology rating
|
6
|
-
And it should have a resources rating
|
7
|
-
And it should have a environment rating
|
8
|
-
|
9
|
-
Scenario: Named Star System Creation
|
10
|
-
When I create a Star System with name "Sparta [T1 E-2 R3]"
|
11
|
-
Then it should have a technology rating of 1
|
12
|
-
And it should have a resources rating of 3
|
13
|
-
And it should have a environment rating of -2
|
@@ -1,16 +0,0 @@
|
|
1
|
-
When /^I create a Star System$/ do
|
2
|
-
current_star_system
|
3
|
-
end
|
4
|
-
|
5
|
-
When /^I create a Star System with (?:the )?name "([^"]*)"$/ do |name|
|
6
|
-
set_current_star_system(name)
|
7
|
-
end
|
8
|
-
|
9
|
-
Then /^it should have an? (#{CAPTURE_SYSTEM_ATTRIBUTE}) rating$/ do |system_attribute|
|
10
|
-
current_star_system.send(system_attribute).must_be :<=, 4
|
11
|
-
current_star_system.send(system_attribute).must_be :>=, -4
|
12
|
-
end
|
13
|
-
|
14
|
-
Then /^it should have an? (#{CAPTURE_SYSTEM_ATTRIBUTE}) rating of (#{CAPTURE_INTEGER})$/ do |system_attribute, rating|
|
15
|
-
current_star_system.send(system_attribute).must_equal rating
|
16
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'dependency_injector'
|
2
|
-
require 'set'
|
3
|
-
require_relative 'fate_dice'
|
4
|
-
|
5
|
-
module Diaspora
|
6
|
-
module Cluster
|
7
|
-
module Creator
|
8
|
-
class Graph
|
9
|
-
extend DependencyInjector
|
10
|
-
def_injector(:dice) { FateDice.new }
|
11
|
-
|
12
|
-
attr_reader :source
|
13
|
-
def initialize(source)
|
14
|
-
@source = source
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
source.to_s
|
19
|
-
end
|
20
|
-
|
21
|
-
def nodes
|
22
|
-
draw!
|
23
|
-
@nodes
|
24
|
-
end
|
25
|
-
|
26
|
-
def edges
|
27
|
-
draw!
|
28
|
-
@edges
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def draw!
|
33
|
-
return if @__drawn__
|
34
|
-
@nodes = source.collect.to_a
|
35
|
-
@nodes.each_with_index do |node, i|
|
36
|
-
result = dice.roll
|
37
|
-
if result < 0
|
38
|
-
connect(node, @nodes[i+1])
|
39
|
-
elsif result == 0
|
40
|
-
connect(node, @nodes[i+1], @nodes[i+2])
|
41
|
-
elsif result > 0
|
42
|
-
connect(node, @nodes[i+1], @nodes[i+2], @nodes[i+3])
|
43
|
-
end
|
44
|
-
end
|
45
|
-
@__drawn__ = true
|
46
|
-
end
|
47
|
-
|
48
|
-
def connect(node, *others)
|
49
|
-
@edges ||= Set.new
|
50
|
-
|
51
|
-
others.flatten.compact.each do |other|
|
52
|
-
@edges << [node,other]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,80 +0,0 @@
|
|
1
|
-
require 'dependency_injector'
|
2
|
-
require 'set'
|
3
|
-
require_relative 'fate_dice'
|
4
|
-
|
5
|
-
module Diaspora
|
6
|
-
module Cluster
|
7
|
-
module Creator
|
8
|
-
class StarSystem
|
9
|
-
def self.rolled_attributes
|
10
|
-
unless defined?(@@rolled_attributes)
|
11
|
-
@@rolled_attributes = Set.new
|
12
|
-
end
|
13
|
-
@@rolled_attributes
|
14
|
-
end
|
15
|
-
def self.rolled_attribute(attribute_name, abbreviation = nil)
|
16
|
-
rolled_attributes << attribute_name.to_s
|
17
|
-
define_method(attribute_name) do
|
18
|
-
instance_variable_get("@#{attribute_name}") || instance_variable_set("@#{attribute_name}", dice.roll)
|
19
|
-
instance_variable_get("@#{attribute_name}")
|
20
|
-
end
|
21
|
-
define_method("#{attribute_name}=") do |value|
|
22
|
-
instance_variable_set("@#{attribute_name}", value.to_i)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
def self.guarantee!(star_systems)
|
26
|
-
return star_systems if star_systems.detect {|ss| ss.technology >= 2 }
|
27
|
-
working = star_systems.sort
|
28
|
-
working.first.technology = 2
|
29
|
-
working.last.technology = 2
|
30
|
-
star_systems
|
31
|
-
end
|
32
|
-
|
33
|
-
extend DependencyInjector
|
34
|
-
def_injector(:dice) { FateDice.new }
|
35
|
-
|
36
|
-
attr_reader :context, :name
|
37
|
-
def initialize(context, name)
|
38
|
-
@context = context
|
39
|
-
set_name(name.to_s)
|
40
|
-
end
|
41
|
-
|
42
|
-
rolled_attribute :technology, :t
|
43
|
-
rolled_attribute :resources, :r
|
44
|
-
rolled_attribute :environment, :e
|
45
|
-
|
46
|
-
include Comparable
|
47
|
-
def <=>(other)
|
48
|
-
to_i <=> other.to_i
|
49
|
-
end
|
50
|
-
|
51
|
-
def to_i
|
52
|
-
self.class.rolled_attributes.inject(0) {|m,v| m += send(v) }
|
53
|
-
end
|
54
|
-
|
55
|
-
def to_s
|
56
|
-
name.to_s
|
57
|
-
end
|
58
|
-
|
59
|
-
def label
|
60
|
-
"#{name}\nT#{technology} R#{resources} E#{environment}"
|
61
|
-
end
|
62
|
-
|
63
|
-
protected
|
64
|
-
def set_name(name_with_attribtes)
|
65
|
-
name, options = name_with_attribtes.strip.split(/ *\[/)
|
66
|
-
@name = name
|
67
|
-
if options
|
68
|
-
options.sub(/\]$/,'').split.collect(&:strip).each do |option|
|
69
|
-
original, attribute_prefix, value = option.match(/(\w) *(-?\d)/).to_a
|
70
|
-
if attribute_name = self.class.rolled_attributes.detect {|roled_attribute| roled_attribute =~ /^#{attribute_prefix}/i}
|
71
|
-
send("#{attribute_name}=",value)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
@name
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper_lite'
|
2
|
-
require 'graph'
|
3
|
-
|
4
|
-
describe Graph do
|
5
|
-
subject { Graph.new(collection) }
|
6
|
-
let(:collection) {[1,2,3]}
|
7
|
-
|
8
|
-
describe '#nodes' do
|
9
|
-
it 'should be the collection of the input' do
|
10
|
-
subject.nodes.must_equal collection
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe '#edges' do
|
15
|
-
it 'connection for all -1 rolls' do
|
16
|
-
expected = Set.new
|
17
|
-
expected << [1,2]
|
18
|
-
expected << [2,3]
|
19
|
-
with_loaded_dice(-1, subject) do
|
20
|
-
subject.edges.must_equal expected
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'connection for all -2 rolls' do
|
25
|
-
expected = Set.new
|
26
|
-
expected << [1,2]
|
27
|
-
expected << [1,3]
|
28
|
-
expected << [2,3]
|
29
|
-
with_loaded_dice(0, subject) do
|
30
|
-
subject.edges.must_equal expected
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
require_relative '../spec_helper_lite'
|
2
|
-
require 'star_system'
|
3
|
-
|
4
|
-
describe StarSystem do
|
5
|
-
subject { StarSystem.new( Object.new, 1 ) }
|
6
|
-
|
7
|
-
describe '#initialize with one attribute' do
|
8
|
-
subject { StarSystem.new(Object.new, "Sparta [T1 E-4]") }
|
9
|
-
it 'should have an extracted name' do
|
10
|
-
subject.name.must_equal 'Sparta'
|
11
|
-
end
|
12
|
-
it 'should have an preset attribute' do
|
13
|
-
with_loaded_dice(0, subject) do
|
14
|
-
subject.resources.must_equal 0
|
15
|
-
subject.technology.must_equal 1
|
16
|
-
subject.environment.must_equal -4
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe '#technology=' do
|
22
|
-
it 'should be overridable' do
|
23
|
-
subject.technology = 3
|
24
|
-
subject.technology.must_equal 3
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
describe '#technology' do
|
29
|
-
it 'should be randomly rolled' do
|
30
|
-
with_loaded_dice(1, subject) do
|
31
|
-
subject.technology.must_equal 1
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe '#resources' do
|
37
|
-
it 'should be randomly rolled' do
|
38
|
-
with_loaded_dice(1, subject) do
|
39
|
-
subject.resources.must_equal 1
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
describe '#environment' do
|
45
|
-
it 'should be randomly rolled' do
|
46
|
-
with_loaded_dice(1, subject) do
|
47
|
-
subject.environment.must_equal 1
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#<=>' do
|
53
|
-
it 'should be comparable to another star system' do
|
54
|
-
@system_a = StarSystem.new('', 1)
|
55
|
-
@system_b = StarSystem.new('', 2)
|
56
|
-
with_loaded_dice(2, @system_a) do
|
57
|
-
with_loaded_dice(1, @system_b) do
|
58
|
-
@system_b.must_be :<, @system_a
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe '.guarantee!' do
|
65
|
-
it 'should adjust technology rating without altering the sort order' do
|
66
|
-
@system_a = StarSystem.new('', 1)
|
67
|
-
@system_b = StarSystem.new('', 2)
|
68
|
-
@system_c = StarSystem.new('', 3)
|
69
|
-
order =
|
70
|
-
with_loaded_dice(1, @system_a) do
|
71
|
-
with_loaded_dice(0, @system_b) do
|
72
|
-
with_loaded_dice(-1, @system_c) do
|
73
|
-
input = [@system_b, @system_c, @system_a]
|
74
|
-
StarSystem.guarantee!(input).must_equal input
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
@system_a.technology.must_equal 2
|
80
|
-
@system_b.technology.must_equal 0
|
81
|
-
@system_c.technology.must_equal 2
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'should not adjust technology rating if one is already adequate' do
|
85
|
-
@system_a = StarSystem.new('', 1)
|
86
|
-
@system_b = StarSystem.new('', 2)
|
87
|
-
@system_c = StarSystem.new('', 3)
|
88
|
-
order =
|
89
|
-
with_loaded_dice(2, @system_a) do
|
90
|
-
with_loaded_dice(0, @system_b) do
|
91
|
-
with_loaded_dice(-1, @system_c) do
|
92
|
-
input = [@system_b, @system_c, @system_a]
|
93
|
-
StarSystem.guarantee!(input).must_equal input
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
@system_a.technology.must_equal 2
|
99
|
-
@system_b.technology.must_equal 0
|
100
|
-
@system_c.technology.must_equal(-1)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|