Files
elixir-koans/lib/watcher.ex
Ian Davies 5556c6bc94 Normalize the file before calling reload.
Fixing: https://github.com/elixirkoans/elixir-koans/issues/138

By normalizing first we remove the IntelliJ specific suffix if it is
present which allows the ".ex" extension to correctly match IntelliJ
edited files.
2017-01-18 22:00:02 -08:00

34 lines
686 B
Elixir

defmodule Watcher do
use ExFSWatch, dirs: ["lib/koans"]
def callback(file, events) do
if Enum.member?(events, :modified) do
file |> normalize |> reload
if Tracker.complete? do
Display.congratulate
exit(:normal)
end
end
end
defp reload(file) do
if Path.extname(file) == ".ex" do
try do
file
|> Code.load_file
|> Enum.map(&(elem(&1, 0)))
|> Enum.find(&Runner.koan?/1)
|> Runner.modules_to_run
|> Runner.run
rescue
e -> Display.show_compile_error(e)
end
end
end
defp normalize(file) do
String.replace_suffix(file, "___jb_tmp___", "")
end
end