-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add check for variable only arguments (#7295)
* Add check for variable only arguemnts * More content * Improve things * Improve example * Simplify next exercise selection * Use 2DP and fix multiplication * WIP * Improve unlocking logic * Fix tests * Update idx * WIP * Updates * Add golf introduction * Double check instructions * Don't show locked exercises * Green
- Loading branch information
Showing
83 changed files
with
1,436 additions
and
417 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class Bootcamp::Exercise::AvailableForUser | ||
include Mandate | ||
|
||
initialize_with :exercise, :user | ||
|
||
def call | ||
# If the exercise is gloabally locked, it's locked | ||
return false if exercise.locked? | ||
|
||
# Otherwise the previous solution must be completed | ||
previous_exercises_completed? | ||
end | ||
|
||
private | ||
delegate :project, to: :exercise | ||
|
||
def previous_exercises_completed? | ||
previous_exercises = project.exercises.where.not(id: exercise.id).select do |prev_ex| | ||
prev_ex.level_idx < exercise.level_idx || | ||
(prev_ex.level_idx == exercise.level_idx && prev_ex.idx < exercise.idx) | ||
end | ||
|
||
completed_exercise_ids = user.bootcamp_solutions.completed.where(exercise_id: previous_exercises.map(&:id)).pluck(:exercise_id) | ||
|
||
previous_exercises.all? { |ex| completed_exercise_ids.include?(ex.id) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,16 @@ | ||
class Bootcamp::SelectNextExercise | ||
include Mandate | ||
|
||
initialize_with :user, project: nil | ||
initialize_with :user | ||
|
||
def call | ||
return next_user_project_exercise if next_user_project_exercise | ||
|
||
Bootcamp::Exercise.unlocked.where.not(project: user.bootcamp_projects). | ||
Bootcamp::Exercise.unlocked. | ||
where.not(id: completed_exercise_ids).first | ||
end | ||
|
||
def user_project | ||
if project | ||
user_project = Bootcamp::UserProject.for!(user, project) | ||
return user_project if user_project.available? | ||
end | ||
|
||
user.bootcamp_user_projects.where(status: :available).first | ||
end | ||
|
||
private | ||
memoize | ||
def next_user_project_exercise = user_project&.next_exercise | ||
|
||
def completed_exercise_ids | ||
user.bootcamp_solutions.where.not(completed_at: nil).select(:exercise_id) | ||
user.bootcamp_solutions.completed.select(:exercise_id) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.