screwcap 0.5 → 0.6.pre

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/History.txt CHANGED
@@ -2,3 +2,6 @@
2
2
 
3
3
  * 1 major enhancement:
4
4
  * Initial release
5
+
6
+ === 0.5 2010-11-19
7
+ * Completed rewrite of internals of screwcap
data/README.rdoc CHANGED
@@ -23,7 +23,6 @@ For more info, see the main screwcap page at http://gammons.github.com/screwcap
23
23
  == TODO:
24
24
  * Explore removing the 'use' keyword, favoring require or load
25
25
  * Add ability to parse user input
26
- * Add ability to parse user input
27
26
  * DONE add --dry-run to screwcap
28
27
 
29
28
  == RECIPES:
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.5'
14
+ self.version = '0.6.pre'
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
@@ -6,8 +6,17 @@ class Task < Screwcap::Base
6
6
  self.__name = opts.delete(:name)
7
7
  self.__options = opts
8
8
  self.__commands = []
9
+ self.__local_before_command_sets = []
10
+ self.__local_after_command_sets = []
9
11
  self.__servers = opts.delete(:servers)
10
12
  self.__block = block
13
+
14
+ if self.__options[:before] and self.__options[:before].class != Array
15
+ self.__options[:before] = [self.__options[:before]]
16
+ end
17
+ if self.__options[:after] and self.__options[:after].class != Array
18
+ self.__options[:after] = [self.__options[:after]]
19
+ end
11
20
  end
12
21
 
13
22
  # Run a command. This can either be a string, or a symbol that is the name of a command set to run.
@@ -78,13 +87,31 @@ class Task < Screwcap::Base
78
87
  end
79
88
  end
80
89
 
90
+ def before name, &block
91
+ self.__local_before_command_sets << Task.new(:name => name, &block)
92
+ end
93
+
94
+ def after name, &block
95
+ self.__local_after_command_sets << Task.new(:name => name, &block)
96
+ end
97
+
98
+
81
99
  def __build_commands(command_sets = [])
82
100
  commands = []
83
101
 
84
102
  self.instance_eval(&self.__block)
85
103
 
86
- # :before for before_ callback
87
- if before = command_sets.find {|cs| cs.__name.to_s == "before_#{self.__name}" or cs.__name == self.__options[:before] } and before != self
104
+ if self.__options[:before]
105
+ self.__options[:before].each do |before|
106
+ before = command_sets.find {|cs| cs.__name.to_s == before.to_s}
107
+ next if before.nil? or before == self
108
+ before.clone_from(self)
109
+ commands << before.__build_commands(command_sets)
110
+ end
111
+ end
112
+
113
+ command_sets.select {|cs| cs.__name.to_s == "before_#{self.__name}"}.each do |before|
114
+ next if before == self
88
115
  before.clone_from(self)
89
116
  commands << before.__build_commands(command_sets)
90
117
  end
@@ -93,7 +120,23 @@ class Task < Screwcap::Base
93
120
  if command[:type] == :unknown
94
121
  if cs = command_sets.find {|cs| cs.__name == command[:command] }
95
122
  cs.clone_from(self)
123
+
124
+ self.__local_before_command_sets.each do |lcs|
125
+ if command[:command] == lcs.__name
126
+ lcs.clone_from(self)
127
+ commands << lcs.__build_commands(command_sets)
128
+ end
129
+ end
130
+
96
131
  commands << cs.__build_commands(command_sets)
132
+
133
+ self.__local_after_command_sets.each do |lcs|
134
+ if command[:command] == lcs.__name
135
+ lcs.clone_from(self)
136
+ commands << lcs.__build_commands(command_sets)
137
+ end
138
+ end
139
+
97
140
  else
98
141
  raise(NoMethodError, "Cannot find task, command set, or other method named '#{command[:command]}'")
99
142
  end
@@ -102,8 +145,17 @@ class Task < Screwcap::Base
102
145
  end
103
146
  end
104
147
 
105
- # :after for after_ callback
106
- if after = command_sets.find {|cs| cs.__name.to_s == "after_#{self.__name}" or cs.__name == self.__options[:after] } and after != self
148
+ if self.__options[:after]
149
+ self.__options[:after].each do |after|
150
+ after = command_sets.find {|cs| cs.__name.to_s == after.to_s}
151
+ next if after.nil? or after == self
152
+ after.clone_from(self)
153
+ commands << after.__build_commands(command_sets)
154
+ end
155
+ end
156
+
157
+ command_sets.select {|cs| cs.__name.to_s == "after_#{self.__name}"}.each do |after|
158
+ next if after == self
107
159
  after.clone_from(self)
108
160
  commands << after.__build_commands(command_sets)
109
161
  end
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.5'
19
+ VERSION='0.6.pre'
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.5"
9
+ s.version = "0.6.pre"
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.author = "Grant Ammons"
12
12
  s.email = ["grant@pipelinedealsco.com"]
data/spec/task_spec.rb CHANGED
@@ -147,4 +147,85 @@ describe "Tasks" do
147
147
  task = Task.new :name => :test, :servers => [:server, :server2]
148
148
  lambda { task.validate([server,other_server]) }.should_not raise_error
149
149
  end
150
+
151
+ it "should handle before and after inside a task" do
152
+ do_other_task = Task.new :name => :other_task do
153
+ run "task"
154
+ end
155
+ task = Task.new :name => :task do
156
+ before :other_task do
157
+ run "before"
158
+ end
159
+ after :other_task do
160
+ run "after"
161
+ end
162
+
163
+ other_task
164
+ end
165
+
166
+ commands = task.__build_commands([do_other_task])
167
+ commands.map {|c| c[:command] }.should == %w(before task after)
168
+ end
169
+
170
+ it "before and after call blocks can call command sets just like everything else" do
171
+ special = Task.new :name => :run_special_command do
172
+ run "special"
173
+ end
174
+ other = Task.new :name => :other_task do
175
+ run "other"
176
+ end
177
+
178
+ task = Task.new :name => :task do
179
+ before :other_task do
180
+ run_special_command
181
+ end
182
+ after :other_task do
183
+ run "after"
184
+ end
185
+ other_task
186
+ end
187
+ commands = task.__build_commands([special, other])
188
+ commands.map {|c| c[:command] }.should == %w(special other after)
189
+ end
190
+
191
+ it "should be able to handle multiple befores inside" do
192
+ special = Task.new :name => :run_special_command do
193
+ run "special"
194
+ end
195
+ other = Task.new :name => :other_task do
196
+ run "other"
197
+ end
198
+
199
+ task = Task.new :name => :task do
200
+ before :other_task do
201
+ run_special_command
202
+ end
203
+ before :other_task do
204
+ run "moon_pie"
205
+ end
206
+ after :other_task do
207
+ run "after"
208
+ end
209
+ other_task
210
+ end
211
+ commands = task.__build_commands([special, other])
212
+ commands.map {|c| c[:command] }.should == %w(special moon_pie other after)
213
+ end
214
+
215
+ it "should be able to handle multiple befores outside" do
216
+ before1 = Task.new :name => :do1 do
217
+ run "do1"
218
+ end
219
+
220
+ before2 = Task.new :name => :do2 do
221
+ run "do2"
222
+ end
223
+
224
+ task = Task.new :name => :new_task, :before => [:do1, :do2] do
225
+ run "task"
226
+ end
227
+
228
+ commands = task.__build_commands([before1, before2])
229
+ commands.map {|c| c[:command] }.should == %w(do1 do2 task)
230
+ end
150
231
  end
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: screwcap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
5
- prerelease: false
4
+ hash: 961915916
5
+ prerelease: true
6
6
  segments:
7
7
  - 0
8
- - 5
9
- version: "0.5"
8
+ - 6
9
+ - pre
10
+ version: 0.6.pre
10
11
  platform: ruby
11
12
  authors:
12
13
  - Grant Ammons
@@ -172,12 +173,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
172
173
  required_rubygems_version: !ruby/object:Gem::Requirement
173
174
  none: false
174
175
  requirements:
175
- - - ">="
176
+ - - ">"
176
177
  - !ruby/object:Gem::Version
177
- hash: 3
178
+ hash: 25
178
179
  segments:
179
- - 0
180
- version: "0"
180
+ - 1
181
+ - 3
182
+ - 1
183
+ version: 1.3.1
181
184
  requirements: []
182
185
 
183
186
  rubyforge_project: screwcap