screwcap 0.6.pre3 → 0.6.pre4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ Hoe.plugin :newgem
11
11
  # Generate all the Rake tasks
12
12
  # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
13
  $hoe = Hoe.spec 'screwcap' do
14
- self.version = '0.6.pre3'
14
+ self.version = '0.6.pre4'
15
15
  self.developer 'Grant Ammons', 'grant@pipelinedeals.com'
16
16
  self.rubyforge_name = self.name # TODO this is default value
17
17
  self.extra_deps = [['net-ssh','>= 2.0.23'],['net-ssh-gateway','>=1.0.1'], ['net-scp','>=1.0.4']]
data/lib/screwcap/task.rb CHANGED
@@ -9,6 +9,7 @@ class Task < Screwcap::Base
9
9
  self.__local_before_command_sets = []
10
10
  self.__local_after_command_sets = []
11
11
  self.__servers = opts.delete(:servers)
12
+ self.__callback = opts.delete(:callback)
12
13
  self.__block = block
13
14
 
14
15
  if self.__options[:before] and self.__options[:before].class != Array
@@ -103,7 +104,7 @@ class Task < Screwcap::Base
103
104
  # end
104
105
 
105
106
  def before name, &block
106
- self.__local_before_command_sets << Task.new(:name => name, &block)
107
+ self.__local_before_command_sets << Task.new(:name => name, :callback => true, &block)
107
108
  end
108
109
 
109
110
  # For a task, declare a set of things to run before or after a command set.
@@ -122,7 +123,7 @@ class Task < Screwcap::Base
122
123
  # end
123
124
 
124
125
  def after name, &block
125
- self.__local_after_command_sets << Task.new(:name => name, &block)
126
+ self.__local_after_command_sets << Task.new(:name => name, :callback => true, &block)
126
127
  end
127
128
 
128
129
  def __build_commands(command_sets = [], _self = self)
@@ -131,21 +132,23 @@ class Task < Screwcap::Base
131
132
  self.__commands = []
132
133
  self.instance_eval(&self.__block)
133
134
 
134
- if self.__options[:before]
135
- self.__options[:before].each do |before|
136
- before = command_sets.find {|cs| cs.__name.to_s == before.to_s}
137
- next if before.nil? or before == self
135
+ unless self.__callback == true
136
+ if self.__options[:before]
137
+ self.__options[:before].each do |before|
138
+ before = command_sets.find {|cs| cs.__name.to_s == before.to_s}
139
+ next if before.nil? or before == self
140
+ before.clone_from(self)
141
+ commands << before.__build_commands(command_sets)
142
+ end
143
+ end
144
+
145
+ command_sets.select {|cs| cs.__name.to_s == "before_#{self.__name}"}.each do |before|
146
+ next if before == self
138
147
  before.clone_from(self)
139
148
  commands << before.__build_commands(command_sets)
140
149
  end
141
150
  end
142
151
 
143
- command_sets.select {|cs| cs.__name.to_s == "before_#{self.__name}"}.each do |before|
144
- next if before == self
145
- before.clone_from(self)
146
- commands << before.__build_commands(command_sets)
147
- end
148
-
149
152
  self.__commands.each do |command|
150
153
  if command[:type] == :unknown
151
154
  if cs = command_sets.find {|cs| cs.__name == command[:command] }
@@ -175,19 +178,21 @@ class Task < Screwcap::Base
175
178
  end
176
179
  end
177
180
 
178
- if self.__options[:after]
179
- self.__options[:after].each do |after|
180
- after = command_sets.find {|cs| cs.__name.to_s == after.to_s}
181
- next if after.nil? or after == self
182
- after.clone_from(self)
183
- commands << after.__build_commands(command_sets)
181
+ unless self.__callback == true
182
+ if self.__options[:after]
183
+ self.__options[:after].each do |after|
184
+ after = command_sets.find {|cs| cs.__name.to_s == after.to_s}
185
+ next if after.nil? or after == self
186
+ after.clone_from(self)
187
+ commands << after.__build_commands(command_sets)
188
+ end
184
189
  end
185
- end
186
190
 
187
- command_sets.select {|cs| cs.__name.to_s == "after_#{self.__name}"}.each do |after|
188
- next if after == self
189
- after.clone_from(self)
190
- commands << after.__build_commands(command_sets, self)
191
+ command_sets.select {|cs| cs.__name.to_s == "after_#{self.__name}"}.each do |after|
192
+ next if after == self
193
+ after.clone_from(self)
194
+ commands << after.__build_commands(command_sets, self)
195
+ end
191
196
  end
192
197
 
193
198
  commands.flatten
data/lib/screwcap.rb CHANGED
@@ -16,7 +16,7 @@ require 'screwcap/sequence'
16
16
  require 'screwcap/task_manager'
17
17
 
18
18
  module Screwcap
19
- VERSION='0.6.pre3'
19
+ VERSION='0.6.pre4'
20
20
 
21
21
  class TaskNotFound < RuntimeError; end
22
22
  class NoServersDefined < Exception; end
data/screwcap.gemspec CHANGED
@@ -6,7 +6,7 @@ require 'bundler/version'
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "screwcap"
9
- s.version = "0.6.pre3"
9
+ s.version = "0.6.pre4"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.author = "Grant Ammons"
12
12
  s.email = ["grant@pipelinedealsco.com"]
@@ -114,4 +114,20 @@ describe "Task Managers" do
114
114
 
115
115
  @tm.run!([:pet_donkey, :pet_global]).map {|c| c[:command] }.should == ["pet donkey","pet monkey"]
116
116
  end
117
+
118
+ it "should not run callback command sets twice" do
119
+ @tm.animal = "monkey"
120
+ @tm.server :server, :address => "test", :user => "root"
121
+ @tm.command_set(:pet_animal) { run "pet_#{animal}" }
122
+ @tm.command_set(:before_pet_animal) { run "prepare_hand" }
123
+
124
+ @tm.task(:pet, :server => :server) do
125
+ before :pet_animal do
126
+ run "put_glove_on_hand"
127
+ end
128
+ pet_animal
129
+ end
130
+
131
+ @tm.run!(:pet).map {|c| c[:command] }.should == %w(put_glove_on_hand prepare_hand pet_monkey)
132
+ end
117
133
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screwcap
3
3
  version: !ruby/object:Gem::Version
4
- hash: -1876988234
4
+ hash: -1876988233
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - pre3
10
- version: 0.6.pre3
9
+ - pre4
10
+ version: 0.6.pre4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Grant Ammons
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-11-20 00:00:00 -05:00
18
+ date: 2010-11-22 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency