analytics/lib/plausible.ex
hq1 88e1d9dc28
Small build updates (#3546)
* Sites API

* Extract Revenue react api helpers

* !fixup

* Extract JS Money module to /extra

* Extract Revenue full build extras (tests pass for full)

* Update MIX_ENV=small mix test

* Remove dead code

* Add moduledocs

* Add credo config

* Trick dialyzer

* DRY revenue metrics

* Use more concise version of on_full_build macro

* Disable credo check
2023-11-22 15:34:47 +01:00

53 lines
1.0 KiB
Elixir

defmodule Plausible do
@moduledoc """
Build-related macros
"""
@small_builds [:small, :small_test]
defmacro __using__(_) do
quote do
require Plausible
import Plausible
end
end
defmacro on_full_build(clauses) do
do_on_full_build(clauses)
end
def do_on_full_build(do: block) do
do_on_full_build(do: block, else: nil)
end
def do_on_full_build(do: do_block, else: else_block) do
if Mix.env() not in @small_builds do
quote do
unquote(do_block)
end
else
quote do
unquote(else_block)
end
end
end
defmacro full_build?() do
full_build? = Mix.env() not in @small_builds
# Tricking dialyzer as per:
# https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778
quote do
:erlang.phash2(1, 1) == 0 and unquote(full_build?)
end
end
defmacro small_build?() do
small_build? = Mix.env() in @small_builds
quote do
unquote(small_build?)
end
end
end