nickstenning-outback 0.0.2 → 0.0.3

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.
@@ -13,18 +13,32 @@ module Outback
13
13
 
14
14
  def initialize
15
15
  @tasks = []
16
+ @names = {}
16
17
  @position = 0
17
18
  end
18
19
 
19
20
  def add_tasks( *tasks )
20
21
  [*tasks].each do |task|
21
22
  task.workdir = @workdir unless task.workdir
23
+
24
+ if task.name
25
+ if @names.has_key?(task.name)
26
+ raise DuplicateNamedTaskError, "Cannot add a named task more than once!"
27
+ else
28
+ @names[task.name] = @tasks.length
29
+ end
30
+ end
31
+
32
+ @tasks << task
22
33
  end
23
- @tasks += [*tasks]
24
34
  end
25
35
 
26
36
  alias_method :add_task, :add_tasks
27
37
 
38
+ def find_task( name )
39
+ @tasks[@names[name]]
40
+ end
41
+
28
42
  def rollout!
29
43
  @direction = ROLLOUT
30
44
  run
@@ -5,7 +5,7 @@ module Outback
5
5
 
6
6
  class ShellTask
7
7
 
8
- attr_accessor :rollout, :rollback, :workdir
8
+ attr_accessor :rollout, :rollback, :workdir, :name
9
9
  attr_reader :result, :errors, :exit_code
10
10
 
11
11
  def initialize(out, back)
data/lib/outback/yaml.rb CHANGED
@@ -6,18 +6,15 @@ module Outback
6
6
  manager = Manager.new
7
7
  tasks = ::YAML.load(yaml_string)
8
8
  tasks.each do |task|
9
+ task = [task['out'], task['back']]
9
10
  manager.tasks << Outback::ShellTask.new(*task)
10
11
  end
11
12
  return manager
12
13
  end
13
14
 
14
15
  def self.load_file( yaml_file )
15
- manager = Manager.new
16
- tasks = ::YAML.load_file(yaml_file)
17
- tasks.each do |task|
18
- manager.tasks << Outback::ShellTask.new(*task)
19
- end
20
- return manager
16
+ yaml = File.read( yaml_file )
17
+ load( yaml )
21
18
  end
22
19
 
23
20
  end
data/lib/outback.rb CHANGED
@@ -6,5 +6,6 @@ module Outback
6
6
 
7
7
  class Error < RuntimeError; end
8
8
  class TransactionError < Error; end
9
+ class DuplicateNamedTaskError < Error; end
9
10
 
10
11
  end
data/outback.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{outback}
3
- s.version = "0.0.2"
3
+ s.version = "0.0.3"
4
4
 
5
5
  s.specification_version = 2 if s.respond_to? :specification_version=
6
6
 
@@ -5,10 +5,9 @@ describe Outback::Manager do
5
5
 
6
6
  before do
7
7
  @obm = Outback::Manager.new
8
- @task1 = mock("task1", :workdir => "/tmp")
9
- @task2 = mock("task2", :workdir => nil)
10
- @task1.stub!(:workdir=)
11
- @task2.stub!(:workdir=)
8
+ @task1 = mock("task1", :workdir => "/tmp", :name => "task1", :null_object => true)
9
+ @task2 = mock("task2", :workdir => nil, :name => nil, :null_object => true)
10
+ @task3 = mock("task3", :workdir => nil, :name => "task3", :null_object => true)
12
11
  end
13
12
 
14
13
  it "should have a list of tasks" do
@@ -24,13 +23,29 @@ describe Outback::Manager do
24
23
  end
25
24
 
26
25
  it "should add multiple tasks to its list, in order, with #add_tasks" do
27
- @obm.add_tasks(@task1, @task2, @task1)
26
+ @obm.add_tasks(@task1, @task2, @task3)
28
27
  @obm.should have(3).tasks
29
28
  @obm.tasks[0].should == @task1
30
29
  @obm.tasks[1].should == @task2
31
- @obm.tasks[2].should == @task1
30
+ @obm.tasks[2].should == @task3
32
31
  end
33
-
32
+
33
+ it "should not allow more than one task with the same name" do
34
+ lambda { @obm.add_tasks(@task1, @task1) }.should raise_error(Outback::DuplicateNamedTaskError)
35
+ lambda { @obm.add_tasks(@task1, @task2, @task1) }.should raise_error(Outback::DuplicateNamedTaskError)
36
+ lambda { @obm.add_tasks(@task1, @task3, @task3) }.should raise_error(Outback::DuplicateNamedTaskError)
37
+ end
38
+
39
+ it "should allow the same task twice if unnamed" do
40
+ lambda { @obm.add_tasks(@task1, @task2, @task2) }.should_not raise_error
41
+ end
42
+
43
+ it "should return the named task with #find_task(name)" do
44
+ @obm.add_tasks(@task1, @task2, @task3)
45
+ @obm.find_task('task1').should == @task1
46
+ @obm.find_task('task3').should == @task3
47
+ end
48
+
34
49
  describe "(with a few tasks)" do
35
50
 
36
51
  before do
@@ -6,6 +6,12 @@ describe Outback::ShellTask do
6
6
  @task = Outback::ShellTask.new("out", "back")
7
7
  end
8
8
 
9
+ it "should have an attr_accessor for @name" do
10
+ @task.name.should be_nil
11
+ @task.name = "Henry"
12
+ @task.name.should == "Henry"
13
+ end
14
+
9
15
  it "should use the first parameter to the rollout command" do
10
16
  @task.rollout.should == "out"
11
17
  end
@@ -6,11 +6,11 @@ describe Outback::YAML do
6
6
  before do
7
7
  @yaml =<<-EOM.gsub(/^\s{4}/, '')
8
8
  -
9
- - touch y
10
- - rm y
9
+ out: touch y
10
+ back: rm y
11
11
  -
12
- - touch x
13
- - rm x
12
+ out: touch x
13
+ back: rm x
14
14
  EOM
15
15
  @file = '/tmp/outback_yaml_spec_tmp'
16
16
  File.open(@file, 'w') { |f| f.puts @yaml }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nickstenning-outback
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Stenning