Created
April 23, 2020 18:47
-
-
Save sb8244/74dcf03e472560ca80bffaf94a73ade1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule SteveTrollsElixir.Private do | |
defmacro __using__(_) do | |
quote do | |
import unquote(__MODULE__) | |
@on_definition {unquote(__MODULE__), :on_priv_def} | |
end | |
end | |
defmacro private() do | |
quote do | |
Module.put_attribute(__MODULE__, :private, true) | |
end | |
end | |
def on_priv_def(%Macro.Env{module: mod}, kind, name, args, _guards, _body) do | |
private_context? = Module.get_attribute(mod, :private) | |
if private_context? && kind != :defp do | |
raise "Defined a public function in a private section. Define #{name}/#{length(args)} above the private definition or mark it defp" | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment