app/models/student.rb
# This progresses the Student's {#lesson_part} to the next one in the series.
#
# The {LessonPart} to progress to is determined according to the following
# business logic:
#
# - if the student has no current lesson, set to {LessonPart.initial};
# - if there is a {LessonPart#next} lesson part, set to that;
# - otherwise, there is no next lesson; raise {Student::AdvanceError}.
#
# This logic is performed in a transaction with a write lock on this record.
#
# @raise [Student::AdvanceError] Raised if there was no {LessonPart} to
#   advance to.
# @return [LessonPart] The new {LessonPart}.
This progresses the Student's {#lesson_part} to the next one in the series.
The {LessonPart} to progress to is determined according to the following
business logic.

if the student has no current lesson, set to {LessonPart.initial};
if there is a {LessonPart#next} lesson part, set to that;
otherwise, there is no next lesson; raise {Student::AdvanceError}.

This logic is performed in a transaction with a write lock on this record.
This progresses the Student ' s { #lesson_part } to the next one in the series . The { LessonPart } to progress to is determined according to the following business logic . if the student has no current lesson set to { LessonPart . initial } ; if there is a { LessonPart#next } lesson part set to that ; otherwise there is no next lesson ; raise { Student :: AdvanceError } . This logic is performed in a transaction with a write lock on this record .
def advance_lesson!
    with_lock do
      next_lesson_part = lesson_part ? lesson_part.next : LessonPart.initial
      raise Student::AdvanceError, 'No LessonPart to advance to' unless next_lesson_part
      update!(lesson_part: next_lesson_part)
      next_lesson_part
    end
  end
def advance_lesson! with_lock do next_lesson_part = lesson_part ? lesson_part . next : LessonPart . initial raise Student :: AdvanceError , 'No LessonPart to advance to' unless next_lesson_part update! ( lesson_part : next_lesson_part ) next_lesson_part end end
This progresses the Student's {#lesson_part} to the next one in the series.
This progresses the Student ' s { #lesson_part } to the next one in the series .
The new {LessonPart}.
The new { LessonPart } .
LessonPart
[Student::AdvanceError] Raised if there was no {LessonPart} to advance to.
[ Student :: AdvanceError ] Raised if there was no { LessonPart } to advance to .