Skip to content

Commit b1a49df

Browse files
author
Kevin Wiesmüller
committed
rename remove method
1 parent 83c7b28 commit b1a49df

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

typed/remove.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ type removingWalker struct {
2424
out interface{}
2525
schema *schema.Schema
2626
toRemove *fieldpath.Set
27-
shallow bool
27+
deep bool
2828
}
2929

30-
func removeItemsWithSchema(val value.Value, toRemove *fieldpath.Set, schema *schema.Schema, typeRef schema.TypeRef, shallow bool) value.Value {
30+
func removeItemsWithSchema(val value.Value, toRemove *fieldpath.Set, schema *schema.Schema, typeRef schema.TypeRef, deep bool) value.Value {
3131
w := &removingWalker{
3232
value: val,
3333
schema: schema,
3434
toRemove: toRemove,
35-
shallow: shallow,
35+
deep: deep,
3636
}
3737
resolveSchema(schema, typeRef, val, w)
3838
return value.NewValueInterface(w.out)
@@ -61,7 +61,7 @@ func (w *removingWalker) doList(t *schema.List) (errs ValidationErrors) {
6161
continue
6262
}
6363
if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
64-
item = removeItemsWithSchema(item, subset, w.schema, t.ElementType, w.shallow)
64+
item = removeItemsWithSchema(item, subset, w.schema, t.ElementType, w.deep)
6565
}
6666
newItems = append(newItems, item.Unstructured())
6767
}
@@ -89,7 +89,7 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
8989
pe := fieldpath.PathElement{FieldName: &k}
9090
path, _ := fieldpath.MakePath(pe)
9191

92-
if w.shallow {
92+
if w.deep {
9393
if w.toRemove.Has(path) {
9494
return true
9595
}
@@ -104,7 +104,7 @@ func (w *removingWalker) doMap(t *schema.Map) ValidationErrors {
104104
}
105105
}
106106
if subset := w.toRemove.WithPrefix(pe); !subset.Empty() {
107-
val = removeItemsWithSchema(val, subset, w.schema, fieldType, w.shallow)
107+
val = removeItemsWithSchema(val, subset, w.schema, fieldType, w.deep)
108108
}
109109
newMap[k] = val.Unstructured()
110110
return true

typed/remove_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func TestRemoveShallowRemovesParents(t *testing.T) {
133133
t.Fatalf("unexpected result after remove:\ngot: %v\nexp: %v", test.String(), expect.String())
134134
}
135135

136-
result = tv.Remove(remove)
136+
result = tv.RemoveDeep(remove)
137137

138138
expect, err = value.FromJSON([]byte(`{"keep": "value", "keepMap": {"child": "value"}, "keepList": [{"child": "value"}]}`))
139139
if err != nil {

typed/typed.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ func (tv TypedValue) RemoveItems(items *fieldpath.Set) *TypedValue {
144144
return &tv
145145
}
146146

147-
// Remove removes each provided path from the value.
148-
func (tv TypedValue) Remove(paths *fieldpath.Set) *TypedValue {
147+
// RemoveDeep removes each provided path from the value, including matching child paths.
148+
// For example `.a` would also remove `.a.b` as it's a child path.
149+
func (tv TypedValue) RemoveDeep(paths *fieldpath.Set) *TypedValue {
149150
tv.value = removeItemsWithSchema(tv.value, paths, tv.schema, tv.typeRef, true)
150151
return &tv
151152
}

0 commit comments

Comments
 (0)