From 04817ff6e8959dc7465a4ee2a2a9205fc4258de3 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 6 Apr 2016 10:08:51 +0100 Subject: [PATCH] Ensure that watcher does not try to run a module that is not a koan --- lib/runner.ex | 4 ++++ lib/watcher.ex | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/runner.ex b/lib/runner.ex index 8deb960..2c84c1b 100644 --- a/lib/runner.ex +++ b/lib/runner.ex @@ -14,6 +14,10 @@ defmodule Runner do Tasks, ] + def koan?(module) do + Enum.member?(@modules, module) + end + def run do Options.initial_koan |>run diff --git a/lib/watcher.ex b/lib/watcher.ex index f131fb6..9914385 100644 --- a/lib/watcher.ex +++ b/lib/watcher.ex @@ -4,8 +4,10 @@ defmodule Watcher do def callback(file, events) do if Enum.member?(events, :modified) do try do - [{mod, _} | _] = Code.load_file(file) - Runner.run(mod) + Code.load_file(file) + |> Enum.map(&(elem(&1, 0))) + |> Enum.find(&Runner.koan?/1) + |> Runner.run rescue e -> Display.show_compile_error(e) end