Skip to content

Instantly share code, notes, and snippets.

@Dkendal
Created September 24, 2020 18:41
Show Gist options
  • Save Dkendal/47c64400735976b60b405f6b84bae04c to your computer and use it in GitHub Desktop.
Save Dkendal/47c64400735976b60b405f6b84bae04c to your computer and use it in GitHub Desktop.
more elixir metaprogramming
defmodule Core.Github do
@behaviour Core.Github.Adapter
for {fun, arity} <- Core.Github.Adapter.behaviour_info(:callbacks) do
args = Macro.generate_arguments(arity, __MODULE__)
@impl true
def unquote(fun)(unquote_splicing(args)) do
apply(adapter(), unquote(fun), unquote(args))
end
end
def adapter() do
Application.fetch_env!(:core, [Core.Github, :api_adapter])
end
@doc """
Creates a new client with the app token.
## Examples
iex> {:app, %{}} = app_client()
"""
def app_client(), do: adapter().app_client(Core.Github.JwtToken.generate_and_sign!())
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment