This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Context do | |
@moduledoc false | |
defmacro __using__(opts) do | |
repo = Keyword.fetch!(opts, :repo) | |
quote do | |
import Context, only: [context: 1, context: 2] | |
Module.put_attribute(__MODULE__, :__repo__, unquote(repo)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Repo do | |
use Ecto.Repo, | |
otp_app: :my_app, | |
adapter: Ecto.Adapters.Postgres | |
require Ecto.Query | |
@spec fetch_one(Ecto.Queryable.t(), Keyword.t()) :: | |
{:ok, struct()} | {:error, :not_found} | |
def fetch_one(queryable, opts \\ []) do |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Normalize do | |
import Ecto.Changeset | |
@spec normalize(map(), Keyword.t()) :: {:ok, map()} | {:error, Ecto.Changeset.t()} | |
def normalize(params, input_schema) do | |
types = | |
Map.new(input_schema, fn {field, opts} -> | |
{field, List.first(opts)} | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule James do | |
@moduledoc """ | |
Agent: James Bond | |
""" | |
defmodule State do | |
@moduledoc """ | |
Data module to defined and modify state. | |
""" | |
defstruct [:id, :name] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use joy) | |
(import markable) | |
(import filesystem) | |
# Layout | |
(defn app-layout [{:body body :request request}] | |
(text/html | |
(doctype :html5) | |
[:html {:lang "en"} | |
[:head |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Storage do | |
@moduledoc """ | |
This module provides a wrapper around the :persistent_term module | |
https://www.erlang.org/doc/man/persistent_term | |
""" | |
@type storage :: atom() | |
@type key :: atom() | |
@type value :: any() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Engine do | |
@moduledoc """ | |
Engine that can run a series of stages. | |
It will return a tuple containing the last effect and all the effects. | |
## Example | |
defmodule HelloWorld do | |
import Engine |