Module: WithMessages

Included in:
Assignment
Defined in:
app/models/concerns/with_messages.rb

Instance Method Summary collapse

Instance Method Details

#build_message(body) ⇒ Object



11
12
13
# File 'app/models/concerns/with_messages.rb', line 11

def build_message(body)
  messages.build({date: Time.current, submission_id: submission_id}.merge(body))
end

#has_messages?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/models/concerns/with_messages.rb', line 15

def has_messages?
  messages.exists?
end

#pending_messages?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/models/concerns/with_messages.rb', line 19

def pending_messages?
  messages.exists? read: false
end

#receive_answer!(answer) ⇒ Object



2
3
4
# File 'app/models/concerns/with_messages.rb', line 2

def receive_answer!(answer)
  build_message(answer).save!
end

#send_question!(question) ⇒ Object



6
7
8
9
# File 'app/models/concerns/with_messages.rb', line 6

def send_question!(question)
  message = build_message question.merge(sender: submitter, read: true)
  message.save_and_notify!
end