On 07/12/11 09:46 , Marc H. wrote:
> Hi,
> I have a general question regarding rake:
>
> Say I have a list of files (based on file extension), that all need to
> be processed in the same way. The output of this processing is required
> by a downstream task. How do I run this in rake?
>
> My approach was:
>
> my_files.each do |file|
>
>   target_file = '#{file}.transformed'
>   file target_file =>  file do
>     # transform here
>   end
>
>   task :transform =>  target_file
> end
>
> next_file = 'transformed_files.txt'
> file next_file =>  :transform do
>   # Do something with all transformed files to produce 1 output file
> end
>
> And this fails, complaining that it does not know how to build
> :transform
>
> Is this a syntactic issue? The workflow above correctly iterates over
> the input files, creates transformed files and then complains that it
> doesn't know how to build :transform. I am at a loss...
> Any 'better' ways of doing this?
>
Actually what I would do in your position would be to create rules 
(since your tasks depend on file extensions):

#this rules says that if a foo.transformed Filetask is called it depends 
on foo.regular
rule ".transformed" => [".regular"] do |r|
  #do the processing here to create the .transformed file
  # r gives you the actual FileTask triggering the rule and you can get 
the path out of it
end

When you have your list of files do

deps=FileList["*.regular"].gsub(".regular",".transformed") #you can 
obviously do all kinds of pathname magic here

and add it to a task

task :transform => deps do
#at this point you know that all transformed files are there and waiting
end

If it's the output file you want to tie up then

file foo.output => deps

Cheers,
V.-

-- 
http://www.ampelofilosofies.gr