rake namespace selection

P

Peter Pk

is there a way to "explicitly" invoke a block inside the scope of a
parent or explicit "root relative" rake namespace instead of always
being a child of the current namespace ???


namespace :xxx do
namespace :yyy do
namespace ...

... called_in_unknown_namespace(arg);

end
end
end


def called_in_unknown_namespace(arg)

# execute below block as if it were in "root" namespace
namespace 'root namespace' do

# declare additional item to do in root namespace task
task :task_in_root do
puts('invoked by "rake task_in_root"');
end
end
# scope restored to wherever you were previously

end

Thanks!
 
P

Peter Pk

Peter said:
is there a way to "explicitly" invoke a block inside the scope of a
parent or explicit "root relative" rake namespace instead of always
being a child of the current namespace ???


namespace :xxx do
namespace :yyy do
namespace ...

... called_in_unknown_namespace(arg);

end
end
end


def called_in_unknown_namespace(arg)

# execute below block as if it were in "root" namespace
namespace 'root namespace' do

# declare additional item to do in root namespace task
task :task_in_root do
puts('invoked by "rake task_in_root"');
end
end
# scope restored to wherever you were previously

end

Thanks!

Ok - figured it out looking at the source, since all tasks simply have
the "scope name" prepended to their name, and the "namespace" is just a
list of names that defines the currnet scope scope in the task manager,
then I was able to do the below to explicitly selct the "global scope".
building the list from a scope name ie: ':name1:name2:name3', '^name'
using the same format as a task name reference will make it general.
BTW what would be appropriate to specify an "absolute path" in rake
convention ???? since namespace :xxx specifies a relative *child* - ie:
desirably somethign like file paths '/' and '..' maybe '::' ???

module Rake
module TaskManager
def in_explicit_namespace(name)
oldscope = @scope;
@scope = Array.new();
# build scope name list from name here
ns = NameSpace.new(self,@scope);
yield(ns)
ns
ensure
@scope = oldscope;
end
end
end

# down below in a rakefile

namespace :num1 do
namespace :num2 do
Rake.application.in_explicit_namespace ':' do
puts("in explicit block");

task :x do |t|
puts(" doing explicit task x");
end
end
end
end

# from command line

$ rake x
doing explicit task x
$
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top