Code.require_file
require_file
, go back to Code module for more information.
Specs
Requires the given file
.
Accepts relative_to
as an argument to tell where the file is located.
If the file was already required, require_file/2
doesn't do anything and
returns nil
.
Note that if require_file/2
is invoked by different processes concurrently,
the first process to invoke require_file/2
acquires a lock and the remaining
ones will block until the file is available. This means that if require_file/2
is called more than once with a given file, that file will be compiled only once.
The first process to call require_file/2
will get the list of loaded modules,
others will get nil
.
See compile_file/2
if you would like to compile a file without tracking its
filenames. Finally, if you would like to get the result of evaluating a file rather
than the modules defined in it, see eval_file/2
.
Examples
If the file has not been required, it returns the list of modules:
modules = Code.require_file("eex_test.exs", "../eex/test")
List.first(modules)
#=> {EExTest.Compiled, <<70, 79, 82, 49, ...>>}
If the file has been required, it returns nil
:
Code.require_file("eex_test.exs", "../eex/test")
#=> nil