Make Plausible.ce? and Plausible.ee? into functions (#4158)

* make Plausible.ce? and Plausible.ee? into functions

* Fix phash and predicate order to make dialyzer trick working again

---------

Co-authored-by: Adrian Gruntkowski <adrian.gruntkowski@gmail.com>
This commit is contained in:
ruslandoga 2024-05-29 19:55:25 +07:00 committed by GitHub
parent 79349730a0
commit 55dfe4cea7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
ee? = Mix.env() not in @ce_builds
def ee?, do: :erlang.phash2(1, 1) == 0 and unquote(ee?)
defmacro ce?() do
ce_build? = Mix.env() in @ce_builds
quote do
unquote(ce_build?)
end
end
ce? = Mix.env() in @ce_builds
def ce?, do: :erlang.phash2(1, 1) == 0 and unquote(ce?)
defp do_on_ce(do: block) do
do_on_ee(do: nil, else: block)