Hook tracker into Execute module via hook
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
defmodule Execute do
|
||||
def run_module(module) do
|
||||
def run_module(module, callback \\ fn(result, koan) -> nil end) do
|
||||
Enum.reduce_while(module.all_koans, :passed, fn(koan, _) ->
|
||||
module
|
||||
|> run_koan(koan)
|
||||
|> hook(koan, callback)
|
||||
|> continue?
|
||||
end)
|
||||
end
|
||||
|
||||
defp hook(result,koan, callback) do
|
||||
callback.(result, koan)
|
||||
result
|
||||
end
|
||||
|
||||
defp continue?(:passed), do: {:cont, :passed}
|
||||
defp continue?(result), do: {:halt, result}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ defmodule Mix.Tasks.Meditate do
|
||||
Code.compiler_options(ignore_module_conflict: true)
|
||||
Watcher.start
|
||||
|
||||
Tracker.start(Runner.modules)
|
||||
Options.start(args)
|
||||
Runner.run
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ defmodule Runner do
|
||||
]
|
||||
|
||||
def koan?(koan), do: Enum.member?(@modules, koan)
|
||||
def modules, do: @modules
|
||||
|
||||
def run do
|
||||
Options.initial_koan
|
||||
@@ -35,11 +36,14 @@ defmodule Runner do
|
||||
def run_module(module) do
|
||||
module
|
||||
|> Display.considering
|
||||
|> Execute.run_module
|
||||
|> Execute.run_module(&track/2)
|
||||
|> display
|
||||
|
||||
end
|
||||
|
||||
defp track(:passed, koan), do: Tracker.completed(koan)
|
||||
defp track(_, _), do: nil
|
||||
|
||||
defp display({:failed, error, module, name}) do
|
||||
Display.show_failure(error, module, name)
|
||||
:failed
|
||||
|
||||
Reference in New Issue
Block a user