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

John Dell spovich at gmail.com
Sun Dec 30 02:09:02 EST 2007


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

----- "Charlie Savage" <cfis at savagexi.com> wrote:
> Hi John,
> 
> Thanks for the code snippet from before - I got a lot of use out of
> it.
> 
> To run it with 0.8.x, the first argument to resolve_args should be an
> 
> array.  So:
> 
>       def self.redefine_task(args, &block)
>         task_name, deps = Rake.application.resolve_args([args])
>         Rake.application.delete_task(task_name)
>         define_task(args, &block)
>       end
> 
> Hope this helps,
> 
> Charlie


More information about the Rake-devel mailing list