lib/screwcap/task.rb in screwcap-0.6.pre3 vs lib/screwcap/task.rb in screwcap-0.6.pre4
- old
+ new
@@ -7,10 +7,11 @@
self.__options = opts
self.__commands = []
self.__local_before_command_sets = []
self.__local_after_command_sets = []
self.__servers = opts.delete(:servers)
+ self.__callback = opts.delete(:callback)
self.__block = block
if self.__options[:before] and self.__options[:before].class != Array
self.__options[:before] = [self.__options[:before]]
end
@@ -101,11 +102,11 @@
# end
# release_the_hounds
# end
def before name, &block
- self.__local_before_command_sets << Task.new(:name => name, &block)
+ self.__local_before_command_sets << Task.new(:name => name, :callback => true, &block)
end
# For a task, declare a set of things to run before or after a command set.
# command_set :release_the_hounds do
# run "release_the_hounds"
@@ -120,34 +121,36 @@
# end
# release_the_hounds
# end
def after name, &block
- self.__local_after_command_sets << Task.new(:name => name, &block)
+ self.__local_after_command_sets << Task.new(:name => name, :callback => true, &block)
end
def __build_commands(command_sets = [], _self = self)
commands = []
self.__commands = []
self.instance_eval(&self.__block)
- if self.__options[:before]
- self.__options[:before].each do |before|
- before = command_sets.find {|cs| cs.__name.to_s == before.to_s}
- next if before.nil? or before == self
+ unless self.__callback == true
+ if self.__options[:before]
+ self.__options[:before].each do |before|
+ before = command_sets.find {|cs| cs.__name.to_s == before.to_s}
+ next if before.nil? or before == self
+ before.clone_from(self)
+ commands << before.__build_commands(command_sets)
+ end
+ end
+
+ command_sets.select {|cs| cs.__name.to_s == "before_#{self.__name}"}.each do |before|
+ next if before == self
before.clone_from(self)
commands << before.__build_commands(command_sets)
end
end
- command_sets.select {|cs| cs.__name.to_s == "before_#{self.__name}"}.each do |before|
- next if before == self
- before.clone_from(self)
- commands << before.__build_commands(command_sets)
- end
-
self.__commands.each do |command|
if command[:type] == :unknown
if cs = command_sets.find {|cs| cs.__name == command[:command] }
cs.clone_from(_self)
@@ -173,22 +176,24 @@
else
commands << command
end
end
- if self.__options[:after]
- self.__options[:after].each do |after|
- after = command_sets.find {|cs| cs.__name.to_s == after.to_s}
- next if after.nil? or after == self
- after.clone_from(self)
- commands << after.__build_commands(command_sets)
+ unless self.__callback == true
+ if self.__options[:after]
+ self.__options[:after].each do |after|
+ after = command_sets.find {|cs| cs.__name.to_s == after.to_s}
+ next if after.nil? or after == self
+ after.clone_from(self)
+ commands << after.__build_commands(command_sets)
+ end
end
- end
- command_sets.select {|cs| cs.__name.to_s == "after_#{self.__name}"}.each do |after|
- next if after == self
- after.clone_from(self)
- commands << after.__build_commands(command_sets, self)
+ command_sets.select {|cs| cs.__name.to_s == "after_#{self.__name}"}.each do |after|
+ next if after == self
+ after.clone_from(self)
+ commands << after.__build_commands(command_sets, self)
+ end
end
commands.flatten
end