Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/tasks/new/exercise.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 9 additions & 10 deletions lib/workshop/exercise.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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