Add basic file watcher to run koans
This commit is contained in:
@@ -2,7 +2,10 @@ defmodule Mix.Tasks.Meditate do
|
||||
use Mix.Task
|
||||
|
||||
def run(_) do
|
||||
Application.ensure_all_started(:elixir_koans)
|
||||
Watcher.start
|
||||
Runner.run
|
||||
:timer.sleep(:infinity)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -7,10 +7,20 @@ defmodule Runner do
|
||||
]
|
||||
|
||||
def run do
|
||||
run(Equalities)
|
||||
end
|
||||
|
||||
def run(start_module) do
|
||||
IO.puts("")
|
||||
Enum.take_while(@modules, fn(mod) ->
|
||||
IO.puts("")
|
||||
|
||||
start_idx = Enum.find_index(@modules, &(&1 == start_module))
|
||||
Enum.drop(@modules, start_idx)
|
||||
|> Enum.take_while(fn(mod) ->
|
||||
run_module(mod) == :passed
|
||||
end)
|
||||
|
||||
IO.puts("")
|
||||
end
|
||||
|
||||
def run_module(module) do
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
defmodule Watcher do
|
||||
use ExFSWatch, dirs: ["lib/koans"]
|
||||
|
||||
def callback(file, events) do
|
||||
if Enum.member?(events, :modified) do
|
||||
[{mod, _}] = Code.load_file(file)
|
||||
Runner.run(mod)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user