strategy 0.1.1 → 0.1.2
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/lib/strategy.rb +28 -0
- data/lib/strategy/plan.rb +8 -8
- data/lib/strategy/step.rb +6 -6
- data/spec/strategy/plan_spec.rb +6 -6
- data/spec/strategy/step_spec.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b90a3cd26bb65310c0188bc84c4c32cf01c6eaa8
|
4
|
+
data.tar.gz: ffe523137e89a5d3514d6eddda99f67f8169af36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46c3eb57bd9e9cd9e19b2c52682d7b92a645db9d996d97b095cf4ede803fd3b157b162198e76f5bdc2d85f9d372c5ac99b7a8c36d4d44b03e89916205b4c7eaf
|
7
|
+
data.tar.gz: 7fd270a4ba0a6ec123948af44beba92c82d91a41ae122cd68e6ef1f1d50e7a719a523560dfe87986c8bc481d6855dd25c238dbe6ef7f2a8d4a161e3e59cfe782
|
data/lib/strategy.rb
CHANGED
@@ -1,2 +1,30 @@
|
|
1
1
|
require 'strategy/step'
|
2
2
|
require 'strategy/plan'
|
3
|
+
|
4
|
+
module Strategy
|
5
|
+
# Convenience function to get a new Step quickly
|
6
|
+
#
|
7
|
+
# == Parameters:
|
8
|
+
# desc::
|
9
|
+
# The description of the new step
|
10
|
+
#
|
11
|
+
# == Returns:
|
12
|
+
# A Strategy::Step with the specified description
|
13
|
+
#
|
14
|
+
def self.step desc
|
15
|
+
Strategy::Step.new desc
|
16
|
+
end
|
17
|
+
|
18
|
+
# Convenience function to get a new Plan quickly
|
19
|
+
#
|
20
|
+
# == Parameters:
|
21
|
+
# desc::
|
22
|
+
# The description of the new plan
|
23
|
+
#
|
24
|
+
# == Returns:
|
25
|
+
# A Strategy::Plan with the specified description
|
26
|
+
#
|
27
|
+
def self.plan desc
|
28
|
+
Strategy::Plan.new desc
|
29
|
+
end
|
30
|
+
end
|
data/lib/strategy/plan.rb
CHANGED
@@ -5,17 +5,17 @@ module Strategy
|
|
5
5
|
# highest-level container around an execution strategy, and may contain as few
|
6
6
|
# or as many Step objects as required.
|
7
7
|
class Plan
|
8
|
-
attr_reader :
|
8
|
+
attr_reader :description, :steps
|
9
9
|
|
10
10
|
# Create a new plan, to which individual execution steps will be added.
|
11
11
|
#
|
12
12
|
# == Parameters:
|
13
|
-
#
|
14
|
-
# The
|
13
|
+
# description::
|
14
|
+
# The description of the execution plan. This is a short sentence which
|
15
15
|
# describes what the plan will do.
|
16
16
|
#
|
17
|
-
def initialize
|
18
|
-
@
|
17
|
+
def initialize description
|
18
|
+
@description = description
|
19
19
|
@steps = []
|
20
20
|
end
|
21
21
|
|
@@ -41,7 +41,7 @@ module Strategy
|
|
41
41
|
@steps.each do |step|
|
42
42
|
n += 1
|
43
43
|
if block_given?
|
44
|
-
yield n, step.
|
44
|
+
yield n, step.description
|
45
45
|
end
|
46
46
|
step.execute!
|
47
47
|
end
|
@@ -51,10 +51,10 @@ module Strategy
|
|
51
51
|
# a textual representation of the execution plan which can be displayed to a
|
52
52
|
# user before executing anything for confirmation.
|
53
53
|
def describe
|
54
|
-
description = [@
|
54
|
+
description = [@description]
|
55
55
|
n = 0
|
56
56
|
@steps.each do |step|
|
57
|
-
description << " #{n+=1}. #{step.
|
57
|
+
description << " #{n+=1}. #{step.description}"
|
58
58
|
end
|
59
59
|
description.join "\n"
|
60
60
|
end
|
data/lib/strategy/step.rb
CHANGED
@@ -3,17 +3,17 @@ module Strategy
|
|
3
3
|
# contains a set of actions, which are the actual pieces of executable
|
4
4
|
# code, as well as a high-level description of what the step accomplishes.
|
5
5
|
class Step
|
6
|
-
attr_reader :
|
6
|
+
attr_reader :description, :actions
|
7
7
|
|
8
8
|
# Creates a new Step, which can later be added to a Plan.
|
9
9
|
#
|
10
10
|
# == Parameters:
|
11
|
-
#
|
12
|
-
# The
|
13
|
-
# step is supposed to accomplish.
|
11
|
+
# description::
|
12
|
+
# The description of the step. This is a high-level description of what
|
13
|
+
# the step is supposed to accomplish.
|
14
14
|
#
|
15
|
-
def initialize
|
16
|
-
@
|
15
|
+
def initialize description
|
16
|
+
@description = description
|
17
17
|
@actions = []
|
18
18
|
end
|
19
19
|
|
data/spec/strategy/plan_spec.rb
CHANGED
@@ -2,29 +2,29 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Plan' do
|
4
4
|
before :all do
|
5
|
-
@plan = Strategy
|
5
|
+
@plan = Strategy.plan 'Test Plan'
|
6
6
|
|
7
|
-
step = Strategy
|
7
|
+
step = Strategy.step 'Step 1'
|
8
8
|
step.action { puts 1 }
|
9
9
|
@plan.add step
|
10
10
|
|
11
|
-
step = Strategy
|
11
|
+
step = Strategy.step 'Step 2'
|
12
12
|
step.action { puts 2 }
|
13
13
|
@plan.add step
|
14
14
|
end
|
15
15
|
|
16
16
|
it 'should add a description to the plan' do
|
17
|
-
expect(@plan.
|
17
|
+
expect(@plan.description).to eq('Test Plan')
|
18
18
|
end
|
19
19
|
|
20
20
|
it 'should accept new steps' do
|
21
|
-
step = Strategy
|
21
|
+
step = Strategy.step 'Step 3'
|
22
22
|
step.action { puts 3 }
|
23
23
|
@plan.add step
|
24
24
|
expect(@plan.steps.length).to eq(3)
|
25
25
|
end
|
26
26
|
|
27
|
-
it 'should reflect the proper plan
|
27
|
+
it 'should reflect the proper plan description' do
|
28
28
|
expect(@plan.describe).to include('Test Plan')
|
29
29
|
end
|
30
30
|
|
data/spec/strategy/step_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Step' do
|
4
4
|
before :all do
|
5
|
-
@step = Strategy
|
5
|
+
@step = Strategy.step 'Test Step'
|
6
6
|
end
|
7
7
|
|
8
|
-
it 'should create a new step with proper
|
9
|
-
expect(@step.
|
8
|
+
it 'should create a new step with proper description' do
|
9
|
+
expect(@step.description).to eq('Test Step')
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'should add an action properly' do
|