lib/screwcap/task.rb in screwcap-0.6.pre vs lib/screwcap/task.rb in screwcap-0.6.pre2
- old
+ new
@@ -85,20 +85,49 @@
else
self.__commands << options.merge({:command => arg, :type => :local, :from => self.__name})
end
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"
+ # end
+ #
+ # task :release do
+ # before :release_the_hounds do
+ # run "unlock_the_gate"
+ # end
+ # after :release_the_hounds do
+ # run "find_and_gather_released_hounds"
+ # end
+ # release_the_hounds
+ # end
+
def before name, &block
self.__local_before_command_sets << Task.new(:name => name, &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"
+ # end
+ #
+ # task :release do
+ # before :release_the_hounds do
+ # run "unlock_the_gate"
+ # end
+ # after :release_the_hounds do
+ # run "find_and_gather_released_hounds"
+ # end
+ # release_the_hounds
+ # end
+
def after name, &block
self.__local_after_command_sets << Task.new(:name => name, &block)
end
-
- def __build_commands(command_sets = [])
+ def __build_commands(command_sets = [], _self = self)
commands = []
self.instance_eval(&self.__block)
if self.__options[:before]
@@ -117,25 +146,25 @@
end
self.__commands.each do |command|
if command[:type] == :unknown
if cs = command_sets.find {|cs| cs.__name == command[:command] }
- cs.clone_from(self)
+ cs.clone_from(_self)
- self.__local_before_command_sets.each do |lcs|
+ _self.__local_before_command_sets.each do |lcs|
if command[:command] == lcs.__name
- lcs.clone_from(self)
- commands << lcs.__build_commands(command_sets)
+ lcs.clone_from(_self)
+ commands << lcs.__build_commands(command_sets, _self)
end
end
- commands << cs.__build_commands(command_sets)
+ commands << cs.__build_commands(command_sets, _self)
- self.__local_after_command_sets.each do |lcs|
+ _self.__local_after_command_sets.each do |lcs|
if command[:command] == lcs.__name
- lcs.clone_from(self)
- commands << lcs.__build_commands(command_sets)
+ lcs.clone_from(_self)
+ commands << lcs.__build_commands(command_sets, _self)
end
end
else
raise(NoMethodError, "Cannot find task, command set, or other method named '#{command[:command]}'")
@@ -155,10 +184,10 @@
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)
+ commands << after.__build_commands(command_sets, self)
end
commands.flatten
end