Getting namespaces from rake

I am trying to automate the process of running all of the rake tasks
within a specific directory. Currently, we have a file that looks like
this:

namespace :myapp do

namespace :bootstrap do

desc "Bootstrap users"
task :users do
end

desc "Bootstrap categories"
task :categories do
end

desc "Bootstrap all"
task :all do
  tasks = %w[users categories]
  tasks.each do |task|
    Rake::Task["myapp:bootstrap:#{task}"].invoke
  end
end

end

end

I would like a way to have the :all task look at the myapp:bootstrap
namespace and provide a list of tasks automatically. We want to avoid
someone adding a bootstrap task and forgetting to add it to the array in
the all task (i.e. %w[…)].

I have read through the rake docs and look at the source, but I’m just
not getting it.

I’ve looked the following:

tasks = Rake::NameSpace(task_manager, "myapp:bootstrap)

Of course, this doesn’t work because I can’t figure out how to get and
use a TaskManager object.

I’m sure there is a way to get the task list other than grepping rake -T
myapp:bootstrap. Can anyone provide some insight? All help
appreciated.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs