module Concerns # Determines whether a participant can access a lesson module Accessibility def accessible? available_for_learning_on <= Date.today end def available_for_learning_on membership.start_date + release_day - 1 end def completed? completed_at.present? end def previous_completed? return false unless learning_task_status_index return true if learning_task_status_first? self .class .find_by_id(learning_task_statuses.ids[learning_task_status_index - 1]) .completed? end private def learning_task_status_first? learning_task_status_index.zero? end def learning_task_status_index learning_task_statuses .ids .find_index(id) end def learning_task_statuses membership .ordered_task_statuses .for_learning end end end