Skip to content

Commit

Permalink
Path: Add new interfaces
Browse files Browse the repository at this point in the history
Also expose component builder to outside

Signed-off-by: Richard Kosegi <richard.kosegi@gmail.com>
  • Loading branch information
rkosegi committed Jul 4, 2024
1 parent 074b38f commit 1dbf454
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
17 changes: 13 additions & 4 deletions path/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,26 @@ func (b *builder) Build() Path {
}

func (b *builder) Append(opts ...AppendOpt) Builder {
b.components = append(b.components, *buildComponent(opts...))
return b
}

// NewBuilder creates new Builder
func NewBuilder() Builder {
return &builder{}
}

func buildComponent(opts ...AppendOpt) *component {
if len(opts) == 0 {
panic("no append option provided by caller")
}
c := &component{}
for _, opt := range opts {
opt(c)
}
b.components = append(b.components, *c)
return b
return c
}

func NewBuilder() Builder {
return &builder{}
func BuildComponent(opts ...AppendOpt) Component {
return buildComponent(opts...)
}
2 changes: 1 addition & 1 deletion path/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestBuilderAppendNoOption(t *testing.T) {
defer func() {
recover()
}()
NewBuilder().Append()
BuildComponent()
assert.Fail(t, "should not be here")
}

Expand Down
12 changes: 12 additions & 0 deletions path/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,15 @@ type Path interface {
}

type AppendOpt func(*component)

// Parser interface is implemented by different Path syntax parsers.
type Parser interface {
// Parse parses source string into Path
Parse(string) (Path, error)
}

// Serializer is interface that allows to serialize Path into lexical form
type Serializer interface {
// Serialize serializes path into lexical representation
Serialize(Path) string
}

0 comments on commit 1dbf454

Please sign in to comment.