From: Peter Pk Date: 2009-05-20T03:41:26+09:00 Subject: Re: rake namespace selection Peter Pk wrote: > > 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 $ -- Posted via http://www.ruby-forum.com/.