Compile-time machinery for AbsinthePermission.
Two responsibilities:
Condition compilation —
compile_condition/2turns a piece of Elixir AST likearg(:state) == "CLOSED"into the data form{:cmp, [:eq, {:arg, :state}, {:literal, "CLOSED"}]}defined byAbsinthePermission.Condition.Schema scope detection —
current_scope/1reads Absinthe's in-progress blueprint to determine the field and type the DSL macro is being expanded inside.
This module is intended to be used by AbsinthePermission.DSL
macros and by the @before_compile hook installed by
use AbsinthePermission. It is not part of the public API.
Summary
Functions
Compile a condition AST into the runtime data form.
Returns {type_identifier, field_identifier} for the field/type the
current macro expansion is inside. Either may be nil if the macro is
used outside an expected scope.
Like current_scope/1 but raises a helpful compile error if the macro
isn't being used inside a schema field or type body.
Types
Functions
@spec compile_condition(Macro.t(), Macro.Env.t()) :: Macro.t()
Compile a condition AST into the runtime data form.
Returns AST that, when evaluated at the call site, produces a
AbsinthePermission.Condition.t/0. Raises CompileError on
malformed input, with file/line from the supplied env.
Examples (the AST input shape, not what users write)
iex> ast = quote do: arg(:state) == "CLOSED"
iex> {:cmp, [:eq, {:arg, :state}, {:literal, "CLOSED"}]} =
...> AbsinthePermission.Compiler.compile_condition(ast, __ENV__)
...> |> Code.eval_quoted([], __ENV__)
...> |> elem(0)
@spec current_scope(Macro.Env.t()) :: scope()
Returns {type_identifier, field_identifier} for the field/type the
current macro expansion is inside. Either may be nil if the macro is
used outside an expected scope.
Reads Module.get_attribute(env.module, :absinthe_blueprint) — that
attribute is populated by Absinthe's notation macros as the schema
compiles.
@spec current_scope!(Macro.Env.t(), atom()) :: scope()
Like current_scope/1 but raises a helpful compile error if the macro
isn't being used inside a schema field or type body.