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 MyApp.Facade do | |
defmacro facade(mod) do | |
quote bind_quoted: [mod: mod] do | |
Enum.each apply(mod, :__info__, [:functions]), fn {fun, arity} -> | |
case arity do | |
0 -> defdelegate unquote(fun)(), to: mod | |
_ -> | |
values = Enum.map(1..arity, &(Macro.var(:"arg#{&1}", mod))) | |
defdelegate unquote(fun)(unquote_splicing(values)), to: mod |