-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Non-empty comment handling refactors
- Loading branch information
Showing
8 changed files
with
63 additions
and
59 deletions.
There are no files selected for viewing
12 changes: 6 additions & 6 deletions
12
common-api/src/main/scala/pl/touk/nussknacker/engine/api/Comment.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
package pl.touk.nussknacker.engine.api | ||
|
||
import io.circe.{Decoder, Encoder} | ||
|
||
final case class Comment private (content: String) extends AnyVal { | ||
class Comment private (val content: String) extends AnyVal { | ||
override def toString: String = content | ||
} | ||
|
||
object Comment { | ||
|
||
def from(content: String): Option[Comment] = { | ||
if (content.isEmpty) None else Some(Comment(content)) | ||
if (content.isEmpty) None else Some(new Comment(content)) | ||
} | ||
|
||
def unsafeFrom(content: String): Comment = { | ||
from(content).getOrElse(throw new IllegalArgumentException("Comment content cannot be empty")) | ||
} | ||
|
||
implicit val encoder: Encoder[Comment] = Encoder.encodeString.contramap(_.content) | ||
implicit val decoder: Decoder[Comment] = Decoder.decodeString.map(Comment.apply) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters