Class: CourseExam::InitializeTopics
- Inherits:
-
Object
- Object
- CourseExam::InitializeTopics
- Defined in:
- app/services/course_exam/initialize_topics.rb
Overview
Initializes topics for a course exam with retake detection.
Responsibilities:
- Detects if the exam is a retake (has failed previous exams)
- For retakes: copies customer_topics from the failed exam (same question order)
- For first attempts: creates customer_topics from the topic_exam definition
- Owns transactional persistence of all changes
Design decision: Retakes reuse the same exam definition with unlimited retakes
and the same question set (decided 2026-07-07). For retakes, we copy the persisted
customer_topics from the failed exam to preserve the question order.
Usage:
CourseExam::InitializeTopics.new(exam, course_enrollment, context_user).call
=> exam (with customer_topics created and persisted)
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(exam, course_enrollment, context_user = nil) ⇒ InitializeTopics
constructor
A new instance of InitializeTopics.
Constructor Details
#initialize(exam, course_enrollment, context_user = nil) ⇒ InitializeTopics
Returns a new instance of InitializeTopics.
20 21 22 23 24 |
# File 'app/services/course_exam/initialize_topics.rb', line 20 def initialize(exam, course_enrollment, context_user = nil) @exam = exam @course_enrollment = course_enrollment @context_user = context_user || course_enrollment.party end |
Instance Method Details
#call ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/course_exam/initialize_topics.rb', line 26 def call ActiveRecord::Base.transaction do failed_exam = find_failed_exam if failed_exam copy_topics_from_failed_exam(failed_exam) else create_topics_from_topic_exam end end @exam end |