Skip to content

Commit c1fac10

Browse files
author
Katrina Owen
committed
Create workspace exercise from metadata
Enhance the ExerciseMetadata type to have a method that creates an exercise given the path to the user's workspace directory.
1 parent a88b3f1 commit c1fac10

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

workspace/exercise_metadata.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,23 @@ func (em *ExerciseMetadata) PathToParent() string {
8787
}
8888
return filepath.Join(dir, em.Track)
8989
}
90+
91+
// Exercise is an implementation of a problem on disk.
92+
func (em *ExerciseMetadata) Exercise(workspace string) Exercise {
93+
return Exercise{
94+
Root: em.root(workspace),
95+
Track: em.Track,
96+
Slug: em.ExerciseSlug,
97+
}
98+
}
99+
100+
// root represents the root of the exercise.
101+
func (em *ExerciseMetadata) root(workspace string) string {
102+
if em.Team != "" {
103+
return filepath.Join(workspace, "teams", em.Team)
104+
}
105+
if !em.IsRequester {
106+
return filepath.Join(workspace, "users", em.Handle)
107+
}
108+
return workspace
109+
}

0 commit comments

Comments
 (0)