Skip to content

Commit

Permalink
Support deprecated status in 48in24 implementation status (exercism#6867
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ErikSchierboom authored Apr 9, 2024
1 parent db2abd8 commit 88523ce
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class User::Challenges::FeaturedExercisesImplementationStatus48In24
include Mandate

initialize_with :featured_exercises, :tracks

def call
tracks.map do |track|
exercises = featured_exercises.map do |featured_exercise|
[featured_exercise[:slug], track_exercise_status(track, featured_exercise)]
end.to_h

[track.slug, exercises]
end.to_h
end

private
def track_exercise_status(track, featured_exercise)
return :featured if featured_exercise[:featured_tracks].include?(track.slug)

exercise_slug = featured_exercise[:slug]
return :do_not_implement if track.foregone_exercises.include?(exercise_slug)

case track_exercises[track.slug][exercise_slug]
when nil
:missing
when 'active', 'beta'
:present
when 'deprecated'
:do_not_implement
end
end

memoize
def track_exercises
Exercise.joins(:track).
where(status: %i[beta active deprecated], track: tracks).
where(slug: featured_exercises.pluck(:slug)).
pluck('tracks.slug', 'exercises.slug', 'exercises.status').
group_by(&:first).
transform_values { |group| group.map { |values| values[1..] }.to_h }
end
end
7 changes: 1 addition & 6 deletions app/controllers/challenges_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,7 @@ def start
def implementation_status
@featured_exercises = User::Challenges::FeaturedExercisesProgress48In24::EXERCISES
@tracks = Track.active.order(:title)
@track_exercises = Exercise.joins(:track).
where(status: %i[beta active], track: @tracks).
where(slug: @featured_exercises.pluck(:slug)).
pluck('tracks.slug', 'exercises.slug').
group_by(&:first).
transform_values { |pairs| pairs.map(&:second) }
@track_exercises_status = User::Challenges::FeaturedExercisesImplementationStatus48In24.(@featured_exercises, @tracks)
end

private
Expand Down
9 changes: 5 additions & 4 deletions app/views/challenges/implementation_status.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,14 @@
%tbody
- @tracks.each do |track|
%tr
- @featured_exercises.each do |featured_exercises|
- @featured_exercises.each do |featured_exercise|
%td.p-8
- if track.foregone_exercises.include?(featured_exercises[:slug])
- case @track_exercises_status[track.slug][featured_exercise[:slug]]
- when :do_not_implement
- elsif featured_exercises[:featured_tracks].include?(track.slug)
- when :featured
💜
- elsif @track_exercises[track.slug].to_a.include?(featured_exercises[:slug])
- when :present
- else

0 comments on commit 88523ce

Please sign in to comment.