Skip to content

Commit

Permalink
Add convention to intelligently select the param converter
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPowers committed May 7, 2021
1 parent 997f254 commit f600f2b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/main/scala/swoop/modelo/Bob.scala
Expand Up @@ -25,7 +25,15 @@ case class Bob(
ParamValidators.requireAtLeastOne(inputParams, requireAtLeastOne)
inputParams.map {
case (key, value) =>
(key, paramConverters(key)(value))
if (key.endsWith("Exact")) {
(key, ParamConverters.exactMatch(value))
} else if (key.endsWith("Exacts")) {
(key, ParamConverters.multiMatch(value))
} else if (paramConverters.contains(key)) {
(key, paramConverters(key)(value))
} else {
(key, ParamConverters.exactMatch(value))
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/test/scala/swoop/modelo/BobSpec.scala
Expand Up @@ -11,13 +11,13 @@ class BobSpec extends FunSpec with Matchers with SparkSessionTestWrapper with Da
val someTool = Bob(
templates = Map("countryFiltered" -> "select * from my_table where country IN {{{countries}}}"),
baseTemplateName = "countryFiltered",
required = Set("whatever", "cool"),
paramConverters = Map("whatever" -> ParamConverters.multiMatch, "cool" -> ParamConverters.exactMatch)
required = Set("whateverExacts", "coolExact")
)
val b = someTool
.whatever("aaa", "bbb")
.cool("ccc")
val expected = Map("whatever" -> "('aaa','bbb')", "cool" -> "'ccc'")
.whateverExacts("aaa", "bbb")
.coolExact("ccc")
.hiExact("hello")
val expected = Map("whateverExacts" -> "('aaa','bbb')", "coolExact" -> "'ccc'", "hiExact" -> "'hello'")
b.attributes should be(expected)
}

Expand Down

0 comments on commit f600f2b

Please sign in to comment.