rake icon indicating copy to clipboard operation
rake copied to clipboard

Is it possible to do on-demand loading of rake tasks?

Open ioquatix opened this issue 8 years ago • 5 comments

And if not, would this be a good idea for a pull request?

ioquatix avatar Dec 08 '16 05:12 ioquatix

Okay just to flesh this out - on-demand loading should minimise the time it takes to load and run tasks when there are hundreds of .rake files

It would only apply to namespaces, and there could either be a dynamic loading scheme or a static loading scheme. Both probably useful as we have a ton of legacy stuff

The idea would be something like this:

For static things:

namespace :db => File.expand_path("db.rake", __dir__)

# When looking up a task in namespace :db, this file would be loaded first.
# Could be multiple things like this, all the files would be loaded.

For dynamic things

namespace File.join(__dir__, "tasks")

# When looking up a namespace which could not be found, try to load tasks/#{namespace.gsub(':', '/')}.rake
# If specified, could be used in combination with above static loading.

Open to ideas, suggestions, etc.

ioquatix avatar Dec 08 '16 07:12 ioquatix

If I can just get a sign that this is something that would be accepted/merged (within reason), I'll work on a PR.

ioquatix avatar Dec 08 '16 07:12 ioquatix

This would be extremely useful! I have previously resorted to manually writing logic in Rakefiles to only load the tasks that are necessary based on the top-level tasks passed in by the user.

shreyasbharath avatar Dec 30 '17 04:12 shreyasbharath

I've created a PR for this purpose: #339.

lionelperrin avatar Feb 18 '20 09:02 lionelperrin

@lionelperrin I like your PR. I also use rake a lot, but I decided to try fixing this in a new gem: https://github.com/ioquatix/bake

ioquatix avatar Feb 18 '20 11:02 ioquatix