Sha256: 1bdca3b19a92fda2606ebfe0245b005d510c3de7b6f5e1749d1fd4e5aac59aee

Contents?: true

Size: 979 Bytes

Versions: 22

Compression:

Stored size: 979 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

  # TODO: When the organization is used in this one, please change guide.pending_exercises
  def find_assignment_for(user, organization)
    assignments.find_by(submitter: user, organization: organization)
  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.build_assignment(self, organization)
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
mumuki-domain-9.12.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.11.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.10.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.9.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.8.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.8.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.7.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.6.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.5.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.4.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.3.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.2.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.2.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.1.2 app/models/concerns/with_assignments.rb
mumuki-domain-9.1.1 app/models/concerns/with_assignments.rb
mumuki-domain-9.1.0 app/models/concerns/with_assignments.rb
mumuki-domain-9.0.6 app/models/concerns/with_assignments.rb
mumuki-domain-9.0.5 app/models/concerns/with_assignments.rb
mumuki-domain-9.0.4 app/models/concerns/with_assignments.rb
mumuki-domain-9.0.3 app/models/concerns/with_assignments.rb