Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

Add withPrefix and withSuffix to Pipeline #376

Merged
merged 1 commit into from
Apr 12, 2020
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
6 changes: 6 additions & 0 deletions core/src/main/scala/dagr/core/tasksystem/Pipeline.scala
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,10 @@ abstract class Pipeline(val outputDirectory: Option[Path] = None,

/** Builds an empty task for use within this pipeline. */
def emptyTask: Task = Task.empty

/** Sets the prefix of this pipeline. */
def withPrefix(prefix: String) : this.type = { this.prefix = Some(prefix); this }

/** Sets the suffix of this pipeline. */
def withSuffix(suffix: String) : this.type = { this.suffix = Some(suffix); this }
}
32 changes: 32 additions & 0 deletions core/src/test/scala/dagr/core/tasksystem/PipelineTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,36 @@ class PipelineTest extends UnitSpec {
ts shouldBe List("outerbefore.innerbefore.hello.outerafter.innerafter",
"outerbefore.innerbefore.world.outerafter.innerafter")
}

it should "add prefix when provided after construction" in {
class TestPipeline extends Pipeline {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withPrefix("new_prefix.").getTasks.map(_.name).toList.sorted
ts shouldBe List("new_prefix.hello", "new_prefix.world")
}

it should "change prefix when provided after construction" in {
class TestPipeline extends Pipeline(prefix=Some("before."), suffix=Some(".after")) {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withPrefix("new_prefix.").getTasks.map(_.name).toList.sorted
ts shouldBe List("new_prefix.hello.after", "new_prefix.world.after")
}

it should "add suffix when provided after construction" in {
class TestPipeline extends Pipeline {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withSuffix(".new_suffix").getTasks.map(_.name).toList.sorted
ts shouldBe List("hello.new_suffix", "world.new_suffix")
}

it should "change suffix when provided after construction" in {
class TestPipeline extends Pipeline(prefix=Some("before."), suffix=Some(".after")) {
override def build(): Unit = root ==> named("hello") ==> named("world")
}
val ts = new TestPipeline().withSuffix(".new_suffix").getTasks.map(_.name).toList.sorted
ts shouldBe List("before.hello.new_suffix", "before.world.new_suffix")
}
}