Is there anyway of specifying alternate prerequisites for a task, ie at
least one of the prerequisites must be run before the task itself is
run.
The way I'm doing it now is by using a "proxy task" that picks one of
the prerequisite tasks based on a global settings variable.
It looks something like this:
===========================================================================
class Settings
def initialize
@supports_rsync = false
@supports_ssh = false
@supports_ftp = false
end
attr_accessor :supports_rsync, :supports_ssh, :supports_ftp
end
settings = Settings.new()
settings.supports_ftp = true
task :backup => [:backup_database, :backup_files] do
#do some stuff
end
task :backup_files do
#do some stuff
if settings.supports_rsync
Rake::Task[:backup_files_with_rsync].invoke
elsif settings.supports_ssh
Rake::Task[:backup_files_with_ssh].invoke
elsif settings.supports_ftp
Rake::Task[:backup_files_with_ftp].invoke
else
puts "raise hell"
end
end
task :backup_database do
puts "backing up the database"
#do some stuff
end
task :backup_files_with_ftp do
puts "backing up the the files with ftp"
#do some stuff
end
task :backup_files_with_ssh do
puts "backing up the the files with ssh"
#do some stuff
end
task :backup_files_with_rsync do
puts "backing up the the files with rsync"
#do some stuff
end
task :default => [:backup] do
end
===========================================================================
This might be OK for a rake file where only one or two tasks has
alternate prerequisites, but for ten or twenty tasks it gets a bit
verbose.
Is there a cleaner way of doing it?
oivvio
--
http://pipedreams.polite.se/about/