From 55dfe4cea7cd13b8b3e46421573bc839836826cc Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Wed, 29 May 2024 19:55:25 +0700 Subject: [PATCH] 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 --- lib/plausible.ex | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/plausible.ex b/lib/plausible.ex index 45eef3a995..b4c9226188 100644 --- a/lib/plausible.ex +++ b/lib/plausible.ex @@ -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)