Class: Smalltalk::Reply

Inherits:
Object
  • Object
show all
Defined in:
lib/smalltalk/reply.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Reply

Returns a new instance of Reply.



5
6
7
8
9
# File 'lib/smalltalk/reply.rb', line 5

def initialize(params = {})
  self.sender = params[:sender]
  self.message = params[:message]
  self.content = params[:content]
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



3
4
5
# File 'lib/smalltalk/reply.rb', line 3

def content
  @content
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/smalltalk/reply.rb', line 3

def message
  @message
end

#senderObject

Returns the value of attribute sender.



3
4
5
# File 'lib/smalltalk/reply.rb', line 3

def sender
  @sender
end

Instance Method Details

#build!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/smalltalk/reply.rb', line 11

def build!
  validate

  reply = Smalltalk::Message.new
  reply.sender = sender
  reply.recipient = message.sender
  reply.content = content
  reply.hidden = false
  reply.viewed = false
  reply.save!

  reply
end

#validateObject

Raises:

  • (HTTPStatus::UnprocessableEntity)


25
26
27
28
29
# File 'lib/smalltalk/reply.rb', line 25

def validate
  raise HTTPStatus::UnprocessableEntity, "No message specified!" if message.blank?
  raise HTTPStatus::UnprocessableEntity, "No sender specified!" if sender.blank?
  raise HTTPStatus::UnprocessableEntity, "No message content was provided!" if content.blank?
end