Skip to content

Commit

Permalink
Merge pull request #1035 from luhring/entry-path-method-export
Browse files Browse the repository at this point in the history
export Path method on configs Entry
  • Loading branch information
luhring authored Jul 7, 2024
2 parents 998fbe4 + dfec729 commit 770ebb0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions pkg/configs/entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Entry[T Configuration] interface {
yamlASTRoot() *yaml.Node

// Path returns the path of the configuration file that underlies this index entry.
getPath() string
Path() string

// Update applies the given entryUpdater to the entry.
Update(ctx context.Context, updater EntryUpdater[T]) error
Expand Down Expand Up @@ -48,7 +48,7 @@ func (e entry[T]) yamlASTRoot() *yaml.Node {
return e.yamlRoot
}

func (e entry[T]) getPath() string {
func (e entry[T]) Path() string {
return e.path
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/configs/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func (i *Index[T]) update(ctx context.Context, entry Entry[T], entryUpdater Entr
}

id := entry.id()
err = i.processAndUpdate(ctx, entry.getPath(), i.byID[id])
err = i.processAndUpdate(ctx, entry.Path(), i.byID[id])
if err != nil {
return fmt.Errorf("unable to process and update index entry for %q: %w", id, err)
}
Expand Down Expand Up @@ -299,7 +299,7 @@ func (i *Index[T]) updateAtIndex(e *entry[T], entryIndex int) {
i.cfgs[entryIndex] = e.cfg
i.byID[e.id()] = entryIndex
i.byName[(*e.Configuration()).Name()] = entryIndex
i.byPath[e.getPath()] = entryIndex
i.byPath[e.Path()] = entryIndex
}

func (i *Index[T]) entry(idx int) Entry[T] {
Expand Down
2 changes: 1 addition & 1 deletion pkg/configs/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (s Selection[T]) WhereName(name string) Selection[T] {
// path match the given parameter.
func (s Selection[T]) WhereFilePath(p string) Selection[T] {
return s.Where(func(e Entry[T]) bool {
return p == e.getPath()
return p == e.Path()
})
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/configs/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ func NewYAMLUpdateFunc[T Configuration](yamlASTMutater YAMLASTMutater[T]) EntryU
return err
}

file, err := i.fsys.OpenAsWritable(e.getPath())
file, err := i.fsys.OpenAsWritable(e.Path())
if err != nil {
return fmt.Errorf("unable to update %q: %w", e.getPath(), err)
return fmt.Errorf("unable to update %q: %w", e.Path(), err)
}
defer file.Close()

err = i.fsys.Truncate(e.getPath(), 0)
err = i.fsys.Truncate(e.Path(), 0)
if err != nil {
return fmt.Errorf("unable to update %q: %w", e.getPath(), err)
return fmt.Errorf("unable to update %q: %w", e.Path(), err)
}

encoder := formatted.NewEncoder(file).AutomaticConfig()
Expand Down

0 comments on commit 770ebb0

Please sign in to comment.