Make the FilterNamespace function the last visitor

This commit is contained in:
derekwaynecarr 2015-01-29 18:00:42 -05:00
parent 4c33e36a88
commit a8449732e0
2 changed files with 12 additions and 0 deletions

View File

@ -402,6 +402,7 @@ func (b *Builder) Do() *Result {
if b.requireNamespace {
helpers = append(helpers, RequireNamespace(b.namespace))
}
helpers = append(helpers, FilterNamespace())
r.visitor = NewDecoratedVisitor(r.visitor, helpers...)
return r
}

View File

@ -384,6 +384,17 @@ func UpdateObjectNamespace(info *Info) error {
return nil
}
// FilterNamespace omits the namespace if the object is not namespace scoped
func FilterNamespace() VisitorFunc {
return func(info *Info) error {
if info.Mapping.Scope.Name() != meta.RESTScopeNameNamespace {
info.Namespace = ""
UpdateObjectNamespace(info)
}
return nil
}
}
// SetNamespace ensures that every Info object visited will have a namespace
// set. If info.Object is set, it will be mutated as well.
func SetNamespace(namespace string) VisitorFunc {