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

Assaf Arkin assaf at labnotes.org
Thu Jan 3 17:57:25 EST 2008


On Jan 3, 2008 2:26 PM, Jim Weirich <jim.weirich at gmail.com> wrote:

>
> On Jan 3, 2008, at 2:55 PM, James Adam wrote:
>
> >> 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 feature.
> >>
> >> 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.
> >
> > I think the engines plugin is looking for option (2), where it's the
> > "body" of the rake task that needs to change, rather than any of the
> > prerequisites.
>
> Actually, that counts as clearing/replacing one of the actions, which
> falls under option (1).
>
> Option (2) is more like you have:
>
>     task "xyz"
>
> and you want to replace it with:
>
>    file "xyz"
>
> Which seems a bizzare thing to do, but I want to ask the question.
>
> > In my specific case, it's really only to add a single
> > line of code to one of the pre-existing rake tasks (as John Dell
> > described earlier).
> >
> > I can see pluses for enabling both (1) and (2) though - certainly in
> > some cases it'd be good to "mock out" the prerequisites of a rake task
> > to test only a single stage. For example:
> >
> > task :process_data => :generate_data do
> >   # do the processing
> > end
> >
> > If the ":generate_data" task takes a long time and/or depends on other
> > inputs, it may be useful to "stub" the :generate_data task to simply
> > copy in some fixture data to where :process_data expects it. Then
> > again, perhaps such "mocking" would be done via re-implementation
> > (i.e. option (2)) anyway?
>
> I'm thinking of something along the lines of:
>
>    task(:generate_data).clear(:actions)
>    task :generate_data do
>      # copy predefined fixtures
>    end
>
> The problem I have with the whole "clear out the task" idea is that
> it doesn't play well with multiple plugins.  Suppose you have the
> following:
>
>    # In the original .rake file:
>    task :generate_data do
>      # Really Generate the data
>    end
>
>    # In plugin number 1, you want to also generate some additional
> data.
>    task :generate_data do
>      # generate some additional data
>    end
>
>    # Now, in plugin number 2, you want to overwrite the original action
>    task(:generate_data).clear(:actions)
>    task :generate_data do
>      # Copy fixtures
>    end
>
> The second plugin not only overwrites the original generate data
> actions as intended, but also any actions added by the first plugin
> (which is probably not intended).
>
> The same issue can happen with prequisites too, where multiple
> plugins clear and and redefine them.  That's one reason I've resisted
> the idea of clearing tasks.  It might solve YOUR issues, but it will
> cause headaches for those using your plugins with other plugins.
>
> Maybe we need pointcuts and AOP for Rake tasks (now my head is
> spinning).


Rake::Task.send :attr_reader, :actions
task('foo').actions.clear
task('bar').actions.unshift lambda { puts 'Me first!' }
task('baz').actions.reverse! # Let's mess with people!

-- 
-- Assaf
http://labnotes.org


--
> -- Jim Weirich
> -- jim.weirich at gmail.com
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/rake-devel/attachments/20080103/0ae3ba1f/attachment.html 


More information about the Rake-devel mailing list