tags:

views:

20

answers:

0

I understand that the file task is executed dependent on some list of monitored files:

file "file_to_edit" => ["a","b"] do
  do_x_here
  sh "echo 'a or b changed' >> file_to_edit"
end

So in this case, if a or b change, then do_x_here is executed as is the sh command.

However, I have a situation where the same file would be changed with two different dependencies, so in this simplified example I'd need to add another file task:

file "file_to_edit" => ["c","d"] do
   do_y_here
   sh "echo 'c or d changed' >> file_to_edit"
end

...but of course, that won't work as coded. So basically, I need to be able to make one set of changes to a file based on the status of one set of files, and another set of changes (and run some set of shell commands - the do_y_here part) to the same file if a different set of files had changed.

Actually, in reality, I don't even need an output file to be modified at this point, it could just be a string that represents the file, but two different gsubs need to be done on the string depending on which set of files has changed. If 'a' or 'b' have changed, then do one gsub and if 'c' or 'd' have changed do another. Then at the end of the modified string can be written out to the target file. So in this case I seem to need a task that's dependent on some set of files changing:

#this is really what I'd like to be able to do:
FILESTRING = File.read("file_to_edit")
task :do_edit_1 => ['a','b'] do  #where 'a' and 'b' are files
  FILESTRING.gsub!(/...some regex.../,"some replacement")
end
task :do_edit_2 => ['c','d'] do  #and 'c' and 'd' are files
  FILESTRING.gsub!(/...some other regex.../,"some other replacement")
end

...but of course, that doesn't work either because tasks are dependent on other tasks not files.