lib/fennel.ex

defmodule Fennel do
  @external_resource readme = Path.join([__DIR__, "../README.md"])

  @moduledoc readme
             |> File.read!()
             |> String.split("<!-- MDOC -->")
             |> Enum.fetch!(1)

  use Supervisor

  def start_link(opts) do
    Supervisor.start_link(__MODULE__, opts, name: __MODULE__)
  end

  def child_spec(opts) do
    opts
    |> super()
    |> Supervisor.child_spec(id: Keyword.get(opts, :name, __MODULE__))
  end

  # TODO: Add config option to disable Cache Supervisor. No point in starting it if it's not used.
  @impl Supervisor
  def init(_) do
    children = [
      {Cachex, name: Fennel.Cache.name()},
      {Fennel.Cache.Observer, []}
    ]

    Supervisor.init(children, strategy: :one_for_one)
  end

  def config_add_typenames, do: Application.get_env(:fennel, :add_typenames, true)

  @cachex_defaults []
  def config_cachex,
    do:
      @cachex_defaults
      |> Keyword.merge(Application.get_env(:fennel, :cachex, []))
end