Module: WithAssignments
- Extended by:
- ActiveSupport::Concern
- Included in:
- Exercise
- Defined in:
- app/models/concerns/with_assignments.rb
Instance Method Summary collapse
- #assigned_to?(user) ⇒ Boolean
- #assignment_for(user) ⇒ Object
- #current_content_for(user) ⇒ Object
- #default_content_for(user) ⇒ Object
- #extra_for(user) ⇒ Object
- #files_for(user) ⇒ Object
- #find_or_init_assignment_for(user) ⇒ Object
- #has_messages_for?(user) ⇒ Boolean
- #interpolate_for(user, field) ⇒ Object
- #last_submission_date_for(user) ⇒ Object
- #messages_for(user) ⇒ Object
- #replace_content_reference(user, interpolee) ⇒ Object
- #solved_by?(user) ⇒ Boolean
- #status_for(user) ⇒ Object
- #submissions_count_for(user) ⇒ Object
Instance Method Details
#assigned_to?(user) ⇒ Boolean
58 59 60 |
# File 'app/models/concerns/with_assignments.rb', line 58 def assigned_to?(user) assignments.exists?(submitter: user) end |
#assignment_for(user) ⇒ Object
50 51 52 |
# File 'app/models/concerns/with_assignments.rb', line 50 def assignment_for(user) assignments.find_by(submitter: user) end |
#current_content_for(user) ⇒ Object
8 9 10 11 |
# File 'app/models/concerns/with_assignments.rb', line 8 def current_content_for(user) assignment_for(user).try(&:solution) || default_content_for(user) end |
#default_content_for(user) ⇒ Object
25 26 27 |
# File 'app/models/concerns/with_assignments.rb', line 25 def default_content_for(user) interpolate_for user, default_content || '' end |
#extra_for(user) ⇒ Object
29 30 31 |
# File 'app/models/concerns/with_assignments.rb', line 29 def extra_for(user) interpolate_for user, extra end |
#files_for(user) ⇒ Object
13 14 15 16 17 18 19 |
# File 'app/models/concerns/with_assignments.rb', line 13 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 |
#find_or_init_assignment_for(user) ⇒ Object
74 75 76 |
# File 'app/models/concerns/with_assignments.rb', line 74 def find_or_init_assignment_for(user) assignment_for(user) || user.assignments.build(exercise: self) end |
#has_messages_for?(user) ⇒ Boolean
46 47 48 |
# File 'app/models/concerns/with_assignments.rb', line 46 def (user) (user).present? end |
#interpolate_for(user, field) ⇒ Object
21 22 23 |
# File 'app/models/concerns/with_assignments.rb', line 21 def interpolate_for(user, field) language.directives_interpolations.interpolate(field, lambda { |content| replace_content_reference(user, content) }).first end |
#last_submission_date_for(user) ⇒ Object
66 67 68 |
# File 'app/models/concerns/with_assignments.rb', line 66 def last_submission_date_for(user) assignment_for(user).try(&:updated_at) end |
#messages_for(user) ⇒ Object
42 43 44 |
# File 'app/models/concerns/with_assignments.rb', line 42 def (user) assignment_for(user)&. || [] end |
#replace_content_reference(user, interpolee) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'app/models/concerns/with_assignments.rb', line 33 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 |
#solved_by?(user) ⇒ Boolean
54 55 56 |
# File 'app/models/concerns/with_assignments.rb', line 54 def solved_by?(user) !!assignment_for(user).try(&:passed?) end |
#status_for(user) ⇒ Object
62 63 64 |
# File 'app/models/concerns/with_assignments.rb', line 62 def status_for(user) assignment_for(user).defaulting(Mumuki::Laboratory::Status::Unknown, &:status) if user end |
#submissions_count_for(user) ⇒ Object
70 71 72 |
# File 'app/models/concerns/with_assignments.rb', line 70 def submissions_count_for(user) assignment_for(user).try(&:submissions_count) || 0 end |