Shows into the first time a module is visted.
This commit is contained in:
@@ -20,6 +20,18 @@ defmodule Display do
|
|||||||
defp name("Elixir." <> module), do: module
|
defp name("Elixir." <> module), do: module
|
||||||
defp name(module), do: name(Atom.to_string(module))
|
defp name(module), do: name(Atom.to_string(module))
|
||||||
|
|
||||||
|
def intro(module) do
|
||||||
|
show_intro(module.intro)
|
||||||
|
module
|
||||||
|
end
|
||||||
|
|
||||||
|
defp show_intro(""), do: nil
|
||||||
|
defp show_intro(message) do
|
||||||
|
message <> "\n"
|
||||||
|
|> Colours.green
|
||||||
|
|> IO.puts
|
||||||
|
end
|
||||||
|
|
||||||
def show_failure(failure, module, name) do
|
def show_failure(failure, module, name) do
|
||||||
IO.puts(format(failure, module, name))
|
IO.puts(format(failure, module, name))
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
defmodule Execute do
|
defmodule Execute do
|
||||||
def run_module(module, callback \\ fn(_result, _koan) -> nil end) do
|
def run_module(module, callback \\ fn(_result, _module, _koan) -> nil end) do
|
||||||
Enum.reduce_while(module.all_koans, :passed, fn(koan, _) ->
|
Enum.reduce_while(module.all_koans, :passed, fn(koan, _) ->
|
||||||
module
|
module
|
||||||
|> run_koan(koan)
|
|> run_koan(koan)
|
||||||
|> hook(koan, callback)
|
|> hook(module, koan, callback)
|
||||||
|> continue?
|
|> continue?
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp hook(result,koan, callback) do
|
defp hook(result, module, koan, callback) do
|
||||||
callback.(result, koan)
|
callback.(result, module, koan)
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ defmodule Runner do
|
|||||||
]
|
]
|
||||||
|
|
||||||
def koan?(koan), do: Enum.member?(@modules, koan)
|
def koan?(koan), do: Enum.member?(@modules, koan)
|
||||||
|
|
||||||
def modules, do: @modules
|
def modules, do: @modules
|
||||||
|
|
||||||
def modules_to_run, do: Options.initial_koan |> modules_to_run
|
def modules_to_run, do: Options.initial_koan |> modules_to_run
|
||||||
@@ -31,16 +32,23 @@ defmodule Runner do
|
|||||||
|
|
||||||
def run_module(module) do
|
def run_module(module) do
|
||||||
module
|
module
|
||||||
|> Execute.run_module(&track/2)
|
|> Execute.run_module(&track/3)
|
||||||
|> display
|
|> display
|
||||||
end
|
end
|
||||||
|
|
||||||
defp track(:passed, koan), do: Tracker.completed(koan)
|
defp track(:passed, module, koan), do: Tracker.completed(module, koan)
|
||||||
defp track(_, _), do: nil
|
defp track(_, _, _), do: nil
|
||||||
|
|
||||||
defp display({:failed, error, module, name}) do
|
defp display({:failed, error, module, name}) do
|
||||||
|
intro(module, Tracker.summarize)
|
||||||
Display.show_failure(error, module, name)
|
Display.show_failure(error, module, name)
|
||||||
:failed
|
:failed
|
||||||
end
|
end
|
||||||
defp display(_), do: :passed
|
defp display(_), do: :passed
|
||||||
|
|
||||||
|
defp intro(module, %{visited_modules: modules}) do
|
||||||
|
if ! module in modules do
|
||||||
|
Display.intro(module)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user