Sha256: 85baac95bab5c454ee204fa115a2cbd05bc9053efa8d319490448ce6d1ad1a74
Contents?: true
Size: 1.81 KB
Versions: 4
Compression:
Stored size: 1.81 KB
Contents
module WithAssignments extend ActiveSupport::Concern included do has_many :assignments, dependent: :destroy end def current_content_for(user) assignment_for(user).try(&:solution) || default_content_for(user) end def files_for(user) language .directives_sections .split_sections(assignment_for(user)&.solution || default_content_for(user)) .except('content') .map { |name, content| struct name: name, content: content } end def interpolate_for(user, field) language.interpolate(field, user.interpolations, lambda { |content| replace_content_reference(user, content) }) end def default_content_for(user) interpolate_for user, default_content || '' end def extra_for(user) interpolate_for user, extra end def replace_content_reference(user, interpolee) case interpolee when /previousContent|previousSolution/ previous.current_content_for(user) when /(solution|content)\[(-?\d*)\]/ sibling_at($2.to_i).current_content_for(user) end end def messages_for(user) assignment_for(user)&.messages || [] end def has_messages_for?(user) messages_for(user).present? end def assignment_for(user) assignments.find_by(submitter: user) end def solved_by?(user) !!assignment_for(user).try(&:passed?) end def assigned_to?(user) assignments.exists?(submitter: user) end def status_for(user) assignment_for(user).defaulting(Mumuki::Laboratory::Status::Submission::Unknown, &:status) if user end def last_submission_date_for(user) assignment_for(user).try(&:updated_at) end def submissions_count_for(user) assignment_for(user).try(&:submissions_count) || 0 end def find_or_init_assignment_for(user) assignment_for(user) || user.assignments.build(exercise: self) end end
Version data entries
4 entries across 4 versions & 1 rubygems