Recently, I've noticed that many of my rake tasks have been getting very
redundant.  I tend to wrap common functionality inside each of my tasks.

Here's a simple example:

task :dosomething do
  tms = Benchmark.measure do
    Lockfile.new("#{RAILS_ROOT}/tmp/do.lock", :retries => 0) do
      puts "Hey, I did something!"
    end
  end
  puts "dosomething took #{tms.to_s}"
end

In this example, I'm benchmarking and outputting how long the task took to
run, as well as creating a lockfile to prevent the task from running more
than once on a machine.  It does get worse from here, as there are many
different tasks that I end up wrapping.  I could create a dependancy, but
there's no way to have other tasks that are run afterward, or with a code
block.

Ideally, this is what I'd like to do:

class BenchmarkFilter
  def filter
      tms = Benchmark.measure do
     yield
    end
    puts "dosomething took #{tms.to_s}"
  end
end

class LockfileFilter
  def filter
    Lockfile.new("#{RAILS_ROOT}/tmp/do.lock", :retries => 0) do
      yield
    end
  end
end

task :dosomething => {:filter => [BenchmarkFilter, LockfileFilter]} do
  puts "Hey, I did something!"
end

Would this syntax make sense for extending rake?  Any other ideas on how I
would implement it?

- scott
_______________________________________________
Rake-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rake-devel

Reply via email to