tango 0.0.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.
- data/.gitignore +3 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +24 -0
- data/Rakefile +10 -0
- data/lib/tango.rb +6 -0
- data/lib/tango/dance.rb +24 -0
- data/lib/tango/dance_builder.rb +13 -0
- data/lib/tango/step.rb +13 -0
- data/lib/tango/step_builder.rb +17 -0
- data/lib/tango/step_runner.rb +40 -0
- data/lib/tango/step_runner_context.rb +13 -0
- data/lib/tango/version.rb +3 -0
- data/spec/dance_spec.rb +86 -0
- data/spec/step_spec.rb +94 -0
- data/tango.gemspec +23 -0
- metadata +93 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
tango (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: http://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.1.2)
|
10
|
+
rspec (2.4.0)
|
11
|
+
rspec-core (~> 2.4.0)
|
12
|
+
rspec-expectations (~> 2.4.0)
|
13
|
+
rspec-mocks (~> 2.4.0)
|
14
|
+
rspec-core (2.4.0)
|
15
|
+
rspec-expectations (2.4.0)
|
16
|
+
diff-lcs (~> 1.1.2)
|
17
|
+
rspec-mocks (2.4.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
rspec
|
24
|
+
tango!
|
data/Rakefile
ADDED
data/lib/tango.rb
ADDED
data/lib/tango/dance.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module Tango
|
2
|
+
class Dance
|
3
|
+
|
4
|
+
class StepAlreadyDefinedError < RuntimeError; end
|
5
|
+
class UndefinedStepError < RuntimeError; end
|
6
|
+
|
7
|
+
def initialize(&block)
|
8
|
+
@steps = {}
|
9
|
+
DanceBuilder.new(self).instance_eval(&block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def define_step(name, step)
|
13
|
+
raise StepAlreadyDefinedError, "Step #{name} already defined" if @steps.has_key?(name)
|
14
|
+
step.dance = self
|
15
|
+
@steps[name] = step
|
16
|
+
end
|
17
|
+
|
18
|
+
def run(step_name, options = {})
|
19
|
+
raise UndefinedStepError, "Step #{step_name} not defined" unless @steps.has_key?(step_name)
|
20
|
+
@steps[step_name].run(options)
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
data/lib/tango/step.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
module Tango
|
2
|
+
class StepRunner
|
3
|
+
|
4
|
+
def initialize(step, options)
|
5
|
+
@step = step
|
6
|
+
@options = options
|
7
|
+
@context = StepRunnerContext.new(@step)
|
8
|
+
end
|
9
|
+
|
10
|
+
def run
|
11
|
+
if @step.met_block
|
12
|
+
run_with_met_block
|
13
|
+
else
|
14
|
+
run_without_met_block
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def run_with_met_block
|
21
|
+
unless met?
|
22
|
+
meet
|
23
|
+
raise "Couldn't meet" unless met?
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def run_without_met_block
|
28
|
+
meet
|
29
|
+
end
|
30
|
+
|
31
|
+
def met?
|
32
|
+
@context.instance_exec(@options, &@step.met_block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def meet
|
36
|
+
@context.instance_exec(@options, &@step.meet_block)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
data/spec/dance_spec.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'tango'
|
2
|
+
|
3
|
+
module Tango
|
4
|
+
describe Dance do
|
5
|
+
|
6
|
+
it "should run a step" do
|
7
|
+
step_run = false
|
8
|
+
|
9
|
+
dance = Dance.new do
|
10
|
+
step "example step" do
|
11
|
+
meet { step_run = true }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
dance.run "example step"
|
16
|
+
step_run.should be_true
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should run one step from within another" do
|
20
|
+
inner_step_run = false
|
21
|
+
|
22
|
+
dance = Dance.new do
|
23
|
+
step "outer step" do
|
24
|
+
meet { run "inner step" }
|
25
|
+
end
|
26
|
+
|
27
|
+
step "inner step" do
|
28
|
+
meet { inner_step_run = true }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
dance.run "outer step"
|
33
|
+
inner_step_run.should be_true
|
34
|
+
end
|
35
|
+
|
36
|
+
context "option passing" do
|
37
|
+
it "should pass options to a step when running" do
|
38
|
+
step_options = { :example => "example" }
|
39
|
+
|
40
|
+
dance = Dance.new do
|
41
|
+
step "example step" do
|
42
|
+
meet {|options| options.should == step_options }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
dance.run "example step", step_options
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should pass options when running other steps" do
|
50
|
+
step_options = { :example => "example" }
|
51
|
+
|
52
|
+
dance = Dance.new do
|
53
|
+
step "outer step" do
|
54
|
+
meet { run "inner step", step_options }
|
55
|
+
end
|
56
|
+
|
57
|
+
step "inner step" do
|
58
|
+
meet {|options| options.should == step_options }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
dance.run "outer step"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "error handling" do
|
67
|
+
it "should raise an error on an attempt to redefine a step" do
|
68
|
+
expect do
|
69
|
+
Dance.new do
|
70
|
+
step "example step" do; end
|
71
|
+
step "example step" do; end
|
72
|
+
end
|
73
|
+
end.should raise_error(Dance::StepAlreadyDefinedError)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should raise an error on an attempt to run an undefined step" do
|
77
|
+
dance = Dance.new do; end
|
78
|
+
|
79
|
+
expect do
|
80
|
+
dance.run "undefined step"
|
81
|
+
end.should raise_error(Dance::UndefinedStepError)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
end
|
86
|
+
end
|
data/spec/step_spec.rb
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'tango'
|
2
|
+
|
3
|
+
module Tango
|
4
|
+
describe Step do
|
5
|
+
|
6
|
+
context "with just a meet block" do
|
7
|
+
it "should run the meet block" do
|
8
|
+
meet_block_calls = 0
|
9
|
+
step = Step.new do
|
10
|
+
meet { meet_block_calls += 1 }
|
11
|
+
end
|
12
|
+
|
13
|
+
step.run
|
14
|
+
meet_block_calls.should == 1
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with a meet block and a met block" do
|
19
|
+
it "should check the met?, run the meet, then check the met? again" do
|
20
|
+
met_block_calls = 0
|
21
|
+
meet_block_calls = 0
|
22
|
+
step = Step.new do
|
23
|
+
met? do
|
24
|
+
met_block_calls += 1
|
25
|
+
meet_block_calls > 0
|
26
|
+
end
|
27
|
+
meet { meet_block_calls += 1 }
|
28
|
+
end
|
29
|
+
|
30
|
+
step.run
|
31
|
+
met_block_calls.should == 2
|
32
|
+
meet_block_calls.should == 1
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should not run the meet if the met? succeeds the first time" do
|
36
|
+
met_block_calls = 0
|
37
|
+
meet_block_calls = 0
|
38
|
+
step = Step.new do
|
39
|
+
met? do
|
40
|
+
met_block_calls += 1
|
41
|
+
true
|
42
|
+
end
|
43
|
+
meet { meet_block_calls += 1 }
|
44
|
+
end
|
45
|
+
|
46
|
+
step.run
|
47
|
+
met_block_calls.should == 1
|
48
|
+
meet_block_calls.should == 0
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should raise if the met? block fails twice" do
|
52
|
+
met_block_calls = 0
|
53
|
+
meet_block_calls = 0
|
54
|
+
step = Step.new do
|
55
|
+
met? do
|
56
|
+
met_block_calls += 1
|
57
|
+
false
|
58
|
+
end
|
59
|
+
meet { meet_block_calls += 1 }
|
60
|
+
end
|
61
|
+
|
62
|
+
expect { step.run }.should raise_error
|
63
|
+
met_block_calls.should == 2
|
64
|
+
meet_block_calls.should == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "run with options" do
|
69
|
+
it "should pass the options to the met block" do
|
70
|
+
step_options = { :example => "example" }
|
71
|
+
|
72
|
+
step = Step.new do
|
73
|
+
met? do |options|
|
74
|
+
options.should == step_options
|
75
|
+
true
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
step.run(step_options)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should pass the options to the meet block" do
|
83
|
+
step_options = { :example => "example" }
|
84
|
+
|
85
|
+
step = Step.new do
|
86
|
+
meet {|options| options.should == step_options }
|
87
|
+
end
|
88
|
+
|
89
|
+
step.run(step_options)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
data/tango.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "tango/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "tango"
|
7
|
+
s.version = Tango::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Pete Yandell"]
|
10
|
+
s.email = ["pete@notahat.com"]
|
11
|
+
s.homepage = ""
|
12
|
+
s.summary = %q{Experiment in deployment tools.}
|
13
|
+
s.description = %q{Experiment in deployment tools, taking ideas from babushka and elsewhere.}
|
14
|
+
|
15
|
+
s.add_development_dependency "rspec"
|
16
|
+
|
17
|
+
s.rubyforge_project = "tango"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,93 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: tango
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Pete Yandell
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-01-17 00:00:00 +11:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
description: Experiment in deployment tools, taking ideas from babushka and elsewhere.
|
34
|
+
email:
|
35
|
+
- pete@notahat.com
|
36
|
+
executables: []
|
37
|
+
|
38
|
+
extensions: []
|
39
|
+
|
40
|
+
extra_rdoc_files: []
|
41
|
+
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- .rspec
|
45
|
+
- Gemfile
|
46
|
+
- Gemfile.lock
|
47
|
+
- Rakefile
|
48
|
+
- lib/tango.rb
|
49
|
+
- lib/tango/dance.rb
|
50
|
+
- lib/tango/dance_builder.rb
|
51
|
+
- lib/tango/step.rb
|
52
|
+
- lib/tango/step_builder.rb
|
53
|
+
- lib/tango/step_runner.rb
|
54
|
+
- lib/tango/step_runner_context.rb
|
55
|
+
- lib/tango/version.rb
|
56
|
+
- spec/dance_spec.rb
|
57
|
+
- spec/step_spec.rb
|
58
|
+
- tango.gemspec
|
59
|
+
has_rdoc: true
|
60
|
+
homepage: ""
|
61
|
+
licenses: []
|
62
|
+
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 0
|
75
|
+
version: "0"
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
none: false
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: tango
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Experiment in deployment tools.
|
91
|
+
test_files:
|
92
|
+
- spec/dance_spec.rb
|
93
|
+
- spec/step_spec.rb
|