def instance(name = nil)
case name
when :root, 'root' then return ROOT
when ArtifactNamespace then return name
when Array then name = name.join(':')
when Module, Project then name = name.name
when :current, 'current', nil then
task = Thread.current[:rake_chain]
task = task.instance_variable_get(:@value) if task
name = case task
when Project then task.name
when Rake::Task then task.scope.join(':')
when nil then Buildr.application.current_scope.join(':')
end
end
name = name.to_s
if name.size == 0
instance = ROOT
else
name = name.to_s
@instances ||= Hash.new { |h, k| h[k] = new(k) }
instance = @instances[name]
end
yield(instance) if block_given?
instance
end