Make code loading compatible and deprecation free on old and new elixirs

This commit is contained in:
Jay Hayes
2019-01-04 08:57:15 -06:00
parent 6c53c51fed
commit 5d4f97a854

View File

@@ -24,7 +24,7 @@ defmodule Watcher do
if Path.extname(file) == ".ex" do
try do
file
|> Code.compile_file()
|> portable_load_file
|> Enum.map(&elem(&1, 0))
|> Enum.find(&Runner.koan?/1)
|> Runner.modules_to_run()
@@ -35,6 +35,17 @@ defmodule Watcher do
end
end
# Elixir 1.7 deprecates Code.load_file in favor of Code.compile_file. In
# order to avoid the depecation warnings while maintaining backwards
# compatibility, we check the sytem version and execute conditionally.
defp portable_load_file(file) do
if Version.match?(System.version(), "~> 1.7") do
Code.compile_file(file)
else
Code.load_file(file)
end
end
defp normalize(file) do
String.replace_suffix(file, "___jb_tmp___", "")
end