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 +1 -1
- data/lib/screwcap/task.rb +28 -23
- data/lib/screwcap.rb +1 -1
- data/screwcap.gemspec +1 -1
- data/spec/task_manager_spec.rb +16 -0
- metadata +4 -4
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.
|
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
|
-
|
135
|
-
self.__options[:before]
|
136
|
-
before
|
137
|
-
|
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
|
-
|
179
|
-
self.__options[:after]
|
180
|
-
after
|
181
|
-
|
182
|
-
|
183
|
-
|
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
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
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
data/screwcap.gemspec
CHANGED
data/spec/task_manager_spec.rb
CHANGED
@@ -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: -
|
4
|
+
hash: -1876988233
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
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-
|
18
|
+
date: 2010-11-22 00:00:00 -05:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|