diff --git a/lib/tasks/new/exercise.ex b/lib/tasks/new/exercise.ex index c18ab2e..c6d4d2b 100644 --- a/lib/tasks/new/exercise.ex +++ b/lib/tasks/new/exercise.ex @@ -12,10 +12,10 @@ defmodule Mix.Tasks.New.Exercise do It expects a name for the new exercise - mix new.workshop NAME + mix new.exercise NAME The path will be named after the given NAME. Given `my_exercise` it will - result in a workshop named *My Exercise*. + result in a exercise named *My Exercise*. The exercises will be ordered by a weight set as a module attribute in the generated *name/exercise.exs* file. It will increment by 1000 for every new diff --git a/lib/workshop/exercise.ex b/lib/workshop/exercise.ex index e62204d..62bc064 100644 --- a/lib/workshop/exercise.ex +++ b/lib/workshop/exercise.ex @@ -188,11 +188,13 @@ defmodule Workshop.Exercise do hints = get(exercise_module, :hint) identifier = get_identifier(exercise_module) - current_exercise_state = exercises_state[identifier] + current_exercise_state = + if Keyword.has_key?(exercises_state[identifier], :hint) do + exercises_state[identifier] + else + Keyword.put(exercises_state[identifier], :hint, 0) + end - unless Keyword.has_key?(current_exercise_state, :hint) do - current_exercise_state = Keyword.put(current_exercise_state, :hint, 0) - end if current_exercise_state[:hint] < length hints do new_state = Keyword.update!(current_exercise_state, :hint, &(&1 + 1)) @@ -218,6 +220,7 @@ defmodule Workshop.Exercise do @spec passes?(String.t) :: boolean def passes?(exercise) do identifier = load(exercise) |> get_identifier + exercises_state = State.get(:exercises, []) unless Keyword.has_key?(exercises_state, identifier) do sandbox_name = exercise_sandbox_name(exercise) exercise_folder = Path.expand(exercise, Workshop.Session.get(:exercises_folder)) @@ -227,13 +230,9 @@ defmodule Workshop.Exercise do Keyword.get(exercises_state[identifier], :status, nil) == :completed end - defp exercises_state, - do: State.get(:exercises, []) - defp map_result(%Result{runs: x, passed: x}), - do: :completed - defp map_result(_), - do: :in_progress + defp map_result(%Result{runs: x, passed: x}), do: :completed + defp map_result(_), do: :in_progress @doc """ Check the user solution against the solution verification script diff --git a/mix.exs b/mix.exs index 98a0764..d4a1375 100644 --- a/mix.exs +++ b/mix.exs @@ -39,5 +39,7 @@ defmodule Workshop.Mixfile do # This project should not have any third-party dependencies as it should # be able to build to, and be distributed as, a mix archive. - defp deps, do: [] + defp deps, do: [ + {:credo, "~> 0.4", only: [:dev, :test]} + ] end