Begin `DotProps` helper to support metta attrs.

mark_as
Rick Carlino 2020-04-30 15:10:34 -05:00
parent 8b48613783
commit e2696cd93b
3 changed files with 23 additions and 2 deletions

View File

@ -1,5 +1,5 @@
defmodule FarmbotCeleryScript.Compiler.UpdateResource do
alias FarmbotCeleryScript.{Compiler, AST}
alias FarmbotCeleryScript.{Compiler, AST, DotProps}
def update_resource(%AST{args: args, body: body}, env) do
quote do
@ -31,7 +31,7 @@ defmodule FarmbotCeleryScript.Compiler.UpdateResource do
IO.puts("TODO: Need to apply handlebars to `value`s.")
key = Map.fetch!(pair.args, :label)
val = Map.fetch!(pair.args, :value)
next_acc = Map.merge(acc, %{key => val})
next_acc = Map.merge(acc, DotProps.create(key, val))
unpair(rest, next_acc)
end

View File

@ -0,0 +1,13 @@
defmodule FarmbotCeleryScript.DotProps do
def create(key, val) do
if String.contains?(key, ".") do
recurse(key, val, %{})
else
%{key => val}
end
end
def recurse(_key, _val, acc) do
acc
end
end

View File

@ -0,0 +1,8 @@
defmodule FarmbotCeleryScript.DotPropsTest do
use ExUnit.Case
alias FarmbotCeleryScript.DotProps
test "converts dotted props to real nested maps" do
assert %{"foo" => "bar"} == DotProps.create("foo", "bar")
end
end