Sha256: 7316a99e9579165462b66595c62792175237c59053159834048476bab666a8e4

Contents?: true

Size: 887 Bytes

Versions: 11

Compression:

Stored size: 887 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, _organization)
    assignments.find_by(submitter: user)
  end

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

  def assignment_for(user, organization: Organization.current)
    find_assignment_for(user, organization) || user.assignments.build(exercise: self, organization: organization)
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
mumuki-laboratory-7.1.0 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-925adf85cca8/app/models/concerns/with_assignments.rb
mumuki-domain-7.1.0 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.0.12 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-74da3d4af98c/app/models/concerns/with_assignments.rb
mumuki-domain-7.0.6 app/models/concerns/with_assignments.rb
mumuki-domain-7.0.5 app/models/concerns/with_assignments.rb
mumuki-domain-7.0.4 app/models/concerns/with_assignments.rb
mumuki-domain-7.0.3 app/models/concerns/with_assignments.rb
mumuki-laboratory-7.0.11 vendor/bundle/ruby/2.3.0/bundler/gems/mumuki-domain-f892f79c60f0/app/models/concerns/with_assignments.rb
mumuki-domain-7.0.2 app/models/concerns/with_assignments.rb
mumuki-domain-7.0.1 app/models/concerns/with_assignments.rb
mumuki-domain-7.0.0 app/models/concerns/with_assignments.rb