Skip to content

Commit 638ba37

Browse files
committed
Cleaning up commits
1 parent f9f8057 commit 638ba37

File tree

6 files changed

+33
-15
lines changed

6 files changed

+33
-15
lines changed

build.sbt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import com.sun.xml.internal.messaging.saaj.util.ByteInputStream
21
import microsites.CdnDirectives
32

4-
import scala.tools.nsc.interpreter.InputStream
5-
63
lazy val root = (project in file("."))
74
.dependsOn(macros)
85
.settings(
@@ -110,4 +107,3 @@ lazy val rootBuildSettings = Seq(
110107
pomIncludeRepository := { _ => false },
111108
publishMavenStyle := true
112109
)
113-

docs/src/main/tut/index.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ A few terrible logging examples :
1717
INFO: The student logged in: scala.Map(...)
1818
INFO: The student logged in: Details("name", "libraryPassword!!")
1919
```
20-
21-
We need more type driven logging, consistent secret management, catching erroneous `toStrings` at compile time, rather than getting shocked and surprised at runtime.
20+
Apart from logging, we have bumped into situations where we tried to concatenate / append "Any"thing using string interpolations, often resulting in logical errors as well.
21+
You know this, we need more type driven logging and string interpolation operations, consistent secret management, catching erroneous `toStrings` at compile time, rather than getting shocked and surprised at runtime.
2222

2323
# Solution
2424

@@ -27,13 +27,13 @@ Easy ! Use `safeStr"your log $a $b, $c"` instead of `s"your log $a $b, $c"` !
2727
Add this in your build.sbt
2828

2929
```scala
30-
libraryDependencies += "io.github.afsalthaj" %% "safe-string" % "1.2.8"
30+
libraryDependencies += "io.github.afsalthaj" %% "safe-string" % "1.2.9"
3131
```
3232

3333
Or, in ammonite;
3434

3535
```scala
36-
@ import $ivy.`io.github.afsalthaj::safe-string:1.2.8`
36+
@ import $ivy.`io.github.afsalthaj::safe-string:1.2.9`
3737
import $ivy.$
3838
```
3939

@@ -83,9 +83,11 @@ scala> safeStr"Doesn't work if there is a non-case class ${nonCaseClass.toString
8383

8484
To understand more on the concepts and usages, please go through:
8585

86-
1) [A Simple Example](https://afsalthaj.github.io/safe-string-interpolation/examples.html)
87-
2) [Typesafe Pretty prints](https://afsalthaj.github.io/safe-string-interpolation/pretty_print.html) and
88-
3) [Logging Secrets / Passwords](https://afsalthaj.github.io/safe-string-interpolation/secrets.html)
86+
- [A Simple Example](https://afsalthaj.github.io/safe-string-interpolation/examples.html)
87+
88+
- [Typesafe Pretty prints](https://afsalthaj.github.io/safe-string-interpolation/pretty_print.html) and
89+
90+
- [Logging Secrets / Passwords](https://afsalthaj.github.io/safe-string-interpolation/secrets.html)
8991

9092
to get started !
9193

docs/src/main/tut/pretty_print.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ Also, if any part of case classes has `Secret`s in it, the value will be hidden.
3737
While the purpose of `safe-string-interpolation` is to make sure you are passing only Strings to `safeStr`, it works for case-class instances as well.
3838
There is a reason for this.
3939

40-
Delegating the job of stringifying a case class to the user has always been an infamous problem and it kills the user's time.
40+
Delegating the job of stringifying a case class to the user has always been an infamous problem and it kills the user's time.
4141
The `safe-string-interpolation` takes up this tedious job, and macros under the hood converts it to a readable string, while hiding `Secret` types.
4242

43+
PS: In the next release, we may ask the user to do `.asStr` explicitly on case classes as well. This will bring in more consistency.
44+
4345
```scala
4446

4547
@ import com.thaj.safe.string.interpolator.SafeString._

macros/src/main/scala/com/thaj/safe/string/interpolator/SafeString.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object SafeString {
5858
val r: Set[c.universe.Tree] =
5959
nextElement.tpe.members.collect {
6060
case CaseClassFieldAndName(nme, typ) =>
61-
q"""com.thaj.safe.string.interpolator.Field(${nme.toString}, $nextElement.$nme)"""
61+
q"""com.thaj.safe.string.interpolator.Field(${nme.toString}, $nextElement.$nme.asStr)"""
6262
}.toSet
6363

6464
val field = q"""com.thaj.safe.string.interpolator.SafeString.Macro.jsonLike($r.map(_.toString))"""

test/src/test/scala/test/com/thaj/safe/string/interpolator/SafeStringSpec.scala

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ package test.com.thaj.safe.string.interpolator
33
import com.thaj.safe.string.interpolator.SafeString._
44
import com.thaj.safe.string.interpolator.Secret
55
import org.specs2.{ScalaCheck, Specification}
6-
import scalaz.NonEmptyList
6+
import scalaz.{@@, NonEmptyList, Tag}
7+
import test.com.thaj.safe.string.interpolator.SafeStringSpec.Xxx.{NewTaggedType, StringTT, StringTTT, TaggedType}
78

89
object SafeStringSpec extends Specification with ScalaCheck {
910
def is =
@@ -18,6 +19,7 @@ object SafeStringSpec extends Specification with ScalaCheck {
1819
SafeString works for GADTs $testGADT
1920
SafeString works for maps in case class $testMap
2021
SafeString works for case class with map and nonemptylist $testMapWithNonEmptyList
22+
SafeString works for case class with tagged type in it $testMultipleTaggedType
2123
"""
2224

2325
final case class Dummy(name: String, age: Int)
@@ -92,4 +94,20 @@ object SafeStringSpec extends Specification with ScalaCheck {
9294
prop { a: String =>
9395
safeStr"works for gadt ${TestMapWithNonEmptyList(Map(a -> NonEmptyList(a, a)))}".string must_=== s"works for gadt { mapN: ${a} -> ${a},${a} }"
9496
}
97+
98+
final case class CaseTag(d: StringTTT, f: StringTT)
99+
100+
object Xxx {
101+
102+
sealed trait TaggedType
103+
type StringTT = String @@ TaggedType
104+
105+
sealed trait NewTaggedType
106+
type StringTTT = String @@ NewTaggedType
107+
}
108+
109+
private def testMultipleTaggedType =
110+
prop { a: String =>
111+
safeStr"works for taggedtypes ${CaseTag(Tag[String, NewTaggedType](a), Tag[String, TaggedType](a))}".string must_=== s"works for taggedtypes { f: ${a}, d: ${a} }"
112+
}
95113
}

version.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version in ThisBuild := "1.2.8"
1+
version in ThisBuild := "1.2.9"

0 commit comments

Comments
 (0)