Skip to content
This repository was archived by the owner on Dec 12, 2025. It is now read-only.

resolver: Refactor visitor pattern#95

Merged
qinqon merged 2 commits intonmstate-archive:mainfrom
qinqon:untangle-resolver
Mar 8, 2022
Merged

resolver: Refactor visitor pattern#95
qinqon merged 2 commits intonmstate-archive:mainfrom
qinqon:untangle-resolver

Conversation

@qinqon
Copy link
Contributor

@qinqon qinqon commented Feb 16, 2022

The code that resolves resolve and filter is mixed up at path.go so for example the replace does not need the shouldFilter feature but still the code that runs it has to understand it.

This PR do the following:

  • Encapsulate the path advancing into the function nextStep and hasMoreSteps
  • Use a map to decide at what part of the path we should filter entries.
  • Create a pair of callbacks for visit a map with an identity and visit a slice when there is no index in the path
  • Move the code from filter/replace to their correct place at filter.go and replace.go, implementing previous callbacks.
  • Replace the "Fn" visit functions with a stateVisitor interface
  • Implement path walk using a pathVisitor

Closes #83

@qinqon qinqon requested a review from AlonaKaplan February 16, 2022 07:08
@netlify
Copy link

netlify bot commented Feb 16, 2022

✔️ Deploy Preview for nmpolicy canceled.

🔨 Explore the source changes: 267574c

🔍 Inspect the deploy log: https://app.netlify.com/sites/nmpolicy/deploys/62135846722fb00008f0e9e6

@qinqon qinqon force-pushed the untangle-resolver branch 3 times, most recently from 518d40b to 267574c Compare February 21, 2022 09:15
@qinqon qinqon changed the title resolver: Move filter/replace code to their correct place resolver: Refactor visitor pattern Feb 21, 2022
@qinqon qinqon force-pushed the untangle-resolver branch 5 times, most recently from 03d494a to 514235e Compare March 1, 2022 12:17
@qinqon qinqon requested a review from AlonaKaplan March 1, 2022 12:19
@qinqon qinqon force-pushed the untangle-resolver branch from 514235e to f621def Compare March 4, 2022 13:08
@qinqon qinqon requested a review from AlonaKaplan March 4, 2022 13:08
The code that resolves resolve and filter is mixed up at path.go so
for example the replace does not need the shouldFilter
feature but still the code that runs it has to understand it.

This change contains the following:

- Encapsulate the path advancing into the function nextStep and hasMoreSteps
  slice when there is no index in the path
- Move the code from filter/replace to their correct place at filter.go
  and replace.go, implementing previous callbacks.
- Replace the "Fn" visit functions with a stateVisitor interface

Signed-off-by: Quique Llorente <ellorent@redhat.com>
@qinqon qinqon force-pushed the untangle-resolver branch 2 times, most recently from 759a246 to b9e3f0d Compare March 8, 2022 11:56
}

func (w walkOpVisitor) visitSlice(p path, sliceToVisit []interface{}) (interface{}, error) {
if p.currentStep.Number == nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this check to accessSliceWithCurrentStep.

Walkind a path is implemented different from the other operators. This
change reuse the same mechanism.

Signed-off-by: Quique Llorente <ellorent@redhat.com>
@qinqon qinqon force-pushed the untangle-resolver branch from b9e3f0d to 8b920b6 Compare March 8, 2022 12:30
@qinqon qinqon merged commit 2ffc142 into nmstate-archive:main Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement walk path with path visitor

2 participants