Skip to content

Commit

Permalink
Make Plausible.ce? and Plausible.ee? into functions (#4158)
Browse files Browse the repository at this point in the history
* make Plausible.ce? and Plausible.ee? into functions

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

---------

Co-authored-by: Adrian Gruntkowski <[email protected]>
  • Loading branch information
ruslandoga and zoldar committed May 29, 2024
1 parent 7934973 commit 55dfe4c
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: :erlang.phash2(1, 1) == 0 and unquote(ee?)

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)
Expand Down

0 comments on commit 55dfe4c

Please sign in to comment.