-
-
Notifications
You must be signed in to change notification settings - Fork 181
/
template_helpers.ex
36 lines (27 loc) · 1.12 KB
/
template_helpers.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
defmodule Ash.Filter.TemplateHelpers do
@moduledoc "Helpers for building filter templates"
defguard is_expr(value)
when is_struct(value, Ash.Query.Not) or is_struct(value, Ash.Query.BooleanExpression) or
is_struct(value, Ash.Query.Call) or is_struct(value, Ash.Query.Ref) or
(is_struct(value) and is_map_key(value, :__predicate__?))
@doc "A helper for using actor values in filter templates"
def actor(value), do: {:_actor, value}
@doc "A helper for using action arguments in filter templates"
def arg(name), do: {:_arg, name}
@doc "A helper for creating a reference"
def ref(name), do: {:_ref, [], name}
@doc "A helper for creating a reference to a related path"
def ref(path, name), do: {:_ref, path, name}
@doc """
A helper for using query context in filter templates
An atom will just get the key, and a list will be accessed via `get_in`.
"""
def context(name), do: {:_context, name}
@doc "A helper for building an expression style filter"
defmacro expr(expr) do
quote do
require Ash.Query
Ash.Query.expr(unquote(expr))
end
end
end