rake icon indicating copy to clipboard operation
rake copied to clipboard

Allow cleaning namespaces.

Open mtuchowski opened this issue 10 years ago • 6 comments

Rake::Task class has a clear() method for removing actions and prerequisites from task. Would it be possible to provide method like this for Rake::NameSpace to remove all tasks?

Also, there is no (at least I couldn't find any) method for searching for namespace like [](task_name) in Rake::Task. There is [](name) method in there, but it searches for task in namespace.

These two features could enable one to write:

Rake::NameSpace.get('namespace_name').clear

Where get is a bad excuse for a method name that returns namespace by name.

mtuchowski avatar Jul 29 '15 20:07 mtuchowski

I would follow Rake::Task's API, so instead of Rake::NameSpace::get, Rake::NameSpace::[] to look up a namespace:

Rake::NameSpace['namespace_name'].clear

drbrain avatar Jul 29 '15 22:07 drbrain

… so I'm for it. Also, there's only one method in Rake that has get in it, which is why I prefer [].

drbrain avatar Jul 29 '15 22:07 drbrain

I wrote get because NameSpace already have [] method that finds tasks in namespace. Changing it's functionality could break API for some people.

mtuchowski avatar Jul 30 '15 07:07 mtuchowski

That one is on a Rake::Namespace instance, the one I propose would be on the Rake::Namespace class. For example:

namespace :n do
  task :t do
    puts 'work'
  end
end

my_namespace = Rake::Namespace['n'] # namespace "n"
my_task = my_namespace['t'] # task "n:t"

This would match Rake::Task['some_task'] (implemented here inside class << self)

drbrain avatar Jul 30 '15 23:07 drbrain

Great. Looks perfect!

mtuchowski avatar Jul 31 '15 06:07 mtuchowski

hey is this already in progress? I just ran into the need for this functionality myself and would be glad to implement it quickly and send a PR if nobody else is working on it

frankpinto avatar Aug 27 '15 18:08 frankpinto