[Rake-devel] redefine rake task broken in 0.8.x for a rails app

Jim Weirich jim.weirich at gmail.com
Wed Jan 2 22:46:28 EST 2008

On Dec 30, 2007, at 2:09 AM, John Dell wrote:
> Hi Charlie,
> Awesome!  That was it.  I also had to change the code for  
> last_comment to last_description.
> I also found that after I fixed my rake task, that the same problem  
> exists in rails engines tasks that is doing the same thing.  I'll  
> post a patch for engines on their forums.
> Thanks,
> John
> Here is the rake task code I'm using now:
> unless Rake::TaskManager.methods.include?(:redefine_task)
>   module Rake
>     module TaskManager
>       def redefine_task(task_class, args, &block)
>         task_name, deps = resolve_args([args])
>         task_name = task_class.scope_name(@scope, task_name)
>         deps = [deps] unless deps.respond_to?(:to_ary)
>         deps = deps.collect {|d| d.to_s }
>         task = @tasks[task_name.to_s] = task_class.new(task_name,  
> self)
>         task.application = self
>         task.add_description(@last_description)
>         @last_description = nil
>         task.enhance(deps, &block)
>         task
>       end
>     end
>     class Task
>       class << self
>         def redefine_task(args, &block)
>           Rake.application.redefine_task(self, args, &block)
>         end
>       end
>     end
>   end
> end

Hmmm ... there are several problem with this patch.  Although it  
works, it doesn't support the new named argument syntax for tasks  
(not that I should talk, I just noticed that the file task in rake  
itself is broken in the same way).

To fix that, change the calling sequence to *args and then the  
resolve_args argument can go back to being just plain args (rather  
than [args]).

But a more fundamental problem is that this code is extremely  
fragile.  Changes to internal rake implementation (such as the 0.7.x  
to 0.8.x) is likely to break this code.

Since redefine/clear_task functionally is something several people  
have asked for, I'm thinking about adding something like that to rake  
directly.  So I'm trying to understand what people need out of this  

Are you trying to ...

(1) Clear existing prerequisites and actions and introduce new ones, or

(2) Completely delete the existing task and replace it with a  
different task (of a possibly different task type)?

If you have use cases for this, I would like to hear them.


-- Jim Weirich
-- jim.weirich at gmail.com

More information about the Rake-devel mailing list