Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Path: Add new interfaces #38

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading