Skip to content

Commit

Permalink
feat: add get value with path function
Browse files Browse the repository at this point in the history
Add a new get value function with a new signature. With this function, a user can dynamically pass a path to obtain a nested property in a given context.
  • Loading branch information
koevskinikola committed Mar 17, 2023
1 parent 730a595 commit f752a6d
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ContextBuiltinFunctions(valueMapper: ValueMapper) {
"get entries" -> List(getEntriesFunction("context"),
getEntriesFunction("m")),
"get value" -> List(getValueFunction(List("m", "key")),
getValueFunction(List("context", "key"))),
getValueFunction(List("context", "key")), getValueFunction2),
"context put" -> List(contextPutFunction, contextPutFunction2),
"put" -> List(contextPutFunction), // deprecated function name
"context merge" -> List(contextMergeFunction),
Expand All @@ -36,13 +36,21 @@ class ContextBuiltinFunctions(valueMapper: ValueMapper) {
private def getValueFunction(parameters: List[String]) = builtinFunction(
params = parameters,
invoke = {
case List(context: ValContext, keys: ValList) => getValueFunction2.invoke(List(context, keys))
case List(ValContext(c), ValString(key)) =>
c.variableProvider
.getVariable(key)
.getOrElse(ValNull)
}
)

private def getValueFunction2 = builtinFunction(
params = List("context", "keys"),
invoke = {
case List(ValContext(context), ValList(keys)) if isListOfStrings(keys) => ???
case List(ValContext(_), ValList(_)) => ValNull
}
)
private def contextPutFunction = builtinFunction(
params = List("context", "key", "value"),
invoke = {
Expand Down

0 comments on commit f752a6d

Please sign in to comment.