TODO: update FarmbotCeleryScript.SysCalls.update_resource/2
parent
c0670ec19a
commit
c3f446d31f
|
@ -1,33 +1,13 @@
|
|||
defmodule FarmbotCeleryScript.Compiler.UpdateResource do
|
||||
alias FarmbotCeleryScript.AST
|
||||
|
||||
def update_resource(ast, _env) do
|
||||
params = destructure_pairs(ast.body, %{})
|
||||
{id, type} = destructure_resource(Map.fetch!(ast.args, :resource))
|
||||
IO.inspect(params)
|
||||
IO.inspect(type)
|
||||
IO.inspect(id)
|
||||
raise "TODO: Convert symbolic `resource` into concrete resource"
|
||||
|
||||
quote do
|
||||
# FarmbotCeleryScript.SysCalls.update_resource(
|
||||
# unquote(Compiler.compile_ast(kind, env)),
|
||||
# unquote(Compiler.compile_ast(id, env)),
|
||||
# unquote(Macro.escape(params))
|
||||
# )
|
||||
FarmbotCeleryScript.SysCalls.update_resource(
|
||||
unquote(Map.fetch!(ast.args, :resource)),
|
||||
unquote(destructure_pairs(ast.body, %{}))
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
defp destructure_resource(%AST{
|
||||
kind: :resource,
|
||||
args: %{
|
||||
resource_id: id,
|
||||
resource_type: type
|
||||
}
|
||||
}) do
|
||||
{type, id}
|
||||
end
|
||||
|
||||
defp destructure_pairs([pair | rest], acc) do
|
||||
IO.puts("TODO: Need to apply handlebars to `value`s.")
|
||||
key = Map.fetch!(pair.args, :label)
|
||||
|
|
|
@ -362,8 +362,28 @@ defmodule FarmbotCeleryScript.CompilerTest do
|
|||
|> Jason.decode!()
|
||||
|> AST.decode()
|
||||
|> compile()
|
||||
assert compiled == strip_nl("""
|
||||
[
|
||||
fn params ->
|
||||
_ = inspect(params)
|
||||
|
||||
assert compiled == strip_nl("?")
|
||||
[
|
||||
fn ->
|
||||
FarmbotCeleryScript.SysCalls.update_resource(
|
||||
%FarmbotCeleryScript.AST{
|
||||
args: %{resource_id: 23, resource_type: "Plant"},
|
||||
body: [],
|
||||
comment: nil,
|
||||
kind: :resource,
|
||||
meta: nil
|
||||
},
|
||||
%{"plant_stage" => "planted", "r" => 23}
|
||||
)
|
||||
end
|
||||
]
|
||||
end
|
||||
]
|
||||
""")
|
||||
end
|
||||
|
||||
defp compile(ast) do
|
||||
|
|
Loading…
Reference in New Issue