Add a default hook name for add_compile_callback
This commit is contained in:
+1
-1
@@ -109,7 +109,7 @@ defmodule Module do
|
||||
# can be updated throughout the module definition and therefore, the final
|
||||
# value of the data can only be compiled using a compiation callback,
|
||||
# which will read the final value of :some_data and compile to a function.
|
||||
def add_compile_callback(module, target, fun) do
|
||||
def add_compile_callback(module, target, fun // :__compiling__) do
|
||||
assert_already_compiled!(:add_compile_callback, module)
|
||||
new = { target, fun }
|
||||
table = table_for(module)
|
||||
|
||||
@@ -5,9 +5,14 @@ defmodule ModuleTest::ToBeUsed do
|
||||
|
||||
def __using__(target) do
|
||||
Module.merge_data target, callback: false
|
||||
Module.add_compile_callback(target, __MODULE__)
|
||||
Module.add_compile_callback(target, __MODULE__, :callback)
|
||||
end
|
||||
|
||||
def __compiling__(target) do
|
||||
Module.merge_data target, compiling: true
|
||||
end
|
||||
|
||||
defmacro callback(target) do
|
||||
value = Orddict.fetch(Module.read_data(target), :callback, nil)
|
||||
Module.merge_data target, callback: true
|
||||
@@ -47,6 +52,10 @@ defmodule ModuleTest do
|
||||
|
||||
def test_compile_callback_hook do
|
||||
false = ModuleTest::ToUse.original_value
|
||||
[callback: true] = ModuleTest::ToUse.__data__
|
||||
true = Orddict.fetch ModuleTest::ToUse.__data__, :callback, false
|
||||
end
|
||||
|
||||
def test_default_compile_callback_hook do
|
||||
true = Orddict.fetch ModuleTest::ToUse.__data__, :compiling, false
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user