Skip to content

Commit

Permalink
make Plausible.ce? and Plausible.ee? into functions
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed May 29, 2024
1 parent 7934973 commit ebefc68
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions lib/plausible.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,14 @@ defmodule Plausible do
do_on_ce(clauses)
end

defmacro ee?() do
ee? = Mix.env() not in @ce_builds
# :erlang.phash2(1, 1) == 0 tricks dialyzer as per:
# https://github.com/elixir-lang/elixir/blob/v1.12.3/lib/elixir/lib/gen_server.ex#L771-L778

# 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(ee?)
end
end

defmacro ce?() do
ce_build? = Mix.env() in @ce_builds
ee? = Mix.env() not in @ce_builds
def ee?, do: unquote(ee?) and :erlang.phash2(1, 1) == 0

quote do
unquote(ce_build?)
end
end
ce? = Mix.env() in @ce_builds
def ce?, do: unquote(ce?) and :erlang.phash2(1, 1) == 0

defp do_on_ce(do: block) do
do_on_ee(do: nil, else: block)
Expand Down

0 comments on commit ebefc68

Please sign in to comment.