Module: WithDiscussions

Extended by:
ActiveSupport::Concern
Included in:
Exercise
Defined in:
app/models/concerns/with_discussions.rb

Instance Method Summary collapse

Instance Method Details

#discuss!(user, discussion, organization = Organization.current) ⇒ Object



9
10
11
# File 'app/models/concerns/with_discussions.rb', line 9

def discuss!(user, discussion, organization = Organization.current)
  new_discussion_for(user, discussion, organization).tap &:save!
end

#new_discussion_for(user, discussion_h = {}, organization = Organization.current) ⇒ Object



21
22
23
24
25
# File 'app/models/concerns/with_discussions.rb', line 21

def new_discussion_for(user, discussion_h = {}, organization = Organization.current)
  discussion_h.merge!(initiator_id: user.id, organization: organization)
  discussion_h.merge!(submission: submission_for(user)) if submission_for(user).present?
  discussions.new discussion_h
end

#submission_for(_) ⇒ Object



13
14
15
# File 'app/models/concerns/with_discussions.rb', line 13

def submission_for(_)
  nil
end

#try_solve_discussions!(user) ⇒ Object



17
18
19
# File 'app/models/concerns/with_discussions.rb', line 17

def try_solve_discussions!(user)
  discussions.where(initiator: user).map(&:try_solve!)
end