Merge pull request #232 from elixirkoans/iamvery/make-code-loading-portable

Make code loading compatible and deprecation free on old and new elixirs
This commit is contained in:
Felipe Seré
2019-01-04 16:02:45 +00:00
committed by GitHub

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