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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user