Sha256: 3e58b681d518e2332e0e17255f841f7046a7c067a451d8515c4db37a975a0a0a

Contents?: true

Size: 794 Bytes

Versions: 35

Compression:

Stored size: 794 Bytes

Contents

module WithAssignments
  extend ActiveSupport::Concern

  # TODO we must avoid _for(user) methods when they
  # are hidden the assignment object, since an assignment already encapsulates
  # the exercise-user pair, and many times they impose a performance hit,
  # since in the normal scenario the assignment object already exists

  included do
    has_many :assignments, dependent: :destroy
  end

  def messages_for(user)
    assignment_for(user).messages
  end

  def has_messages_for?(user)
    messages_for(user).present?
  end

  def find_assignment_for(user)
    assignments.find_by(submitter: user)
  end

  def status_for(user)
    assignment_for(user).status if user
  end

  def assignment_for(user)
    find_assignment_for(user) || user.assignments.build(exercise: self)
  end
end

Version data entries

35 entries across 35 versions & 2 rubygems

Version Path
mumuki-domain-6.7.2 app/models/concerns/with_assignments.rb
mumuki-domain-6.7.1 app/models/concerns/with_assignments.rb
mumuki-domain-6.7.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.6.2 app/models/concerns/with_assignments.rb
mumuki-domain-6.6.1 app/models/concerns/with_assignments.rb
mumuki-domain-6.6.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.5.1 app/models/concerns/with_assignments.rb
mumuki-domain-6.5.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.4.3 app/models/concerns/with_assignments.rb
mumuki-domain-6.4.2 app/models/concerns/with_assignments.rb
mumuki-domain-6.4.1 app/models/concerns/with_assignments.rb
mumuki-domain-6.4.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.2.2 app/models/concerns/with_assignments.rb
mumuki-domain-6.2.1 app/models/concerns/with_assignments.rb
mumuki-domain-6.3.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.2.0 app/models/concerns/with_assignments.rb
mumuki-domain-6.1.5 app/models/concerns/with_assignments.rb
mumuki-domain-6.0.4 app/models/concerns/with_assignments.rb
mumuki-domain-6.1.4 app/models/concerns/with_assignments.rb
mumuki-domain-6.1.3 app/models/concerns/with_assignments.rb