Class: DispatchRider::Message

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Validations
Defined in:
lib/dispatch-rider/message.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Message

Returns a new instance of Message.

Raises:



13
14
15
16
17
18
# File 'lib/dispatch-rider/message.rb', line 13

def initialize(options)
  attrs = options.symbolize_keys
  @subject = attrs[:subject]
  @body = attrs[:body] || {}
  raise RecordInvalid.new(self, errors.full_messages) unless valid?
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



9
10
11
# File 'lib/dispatch-rider/message.rb', line 9

def body
  @body
end

#subjectObject

Returns the value of attribute subject.



9
10
11
# File 'lib/dispatch-rider/message.rb', line 9

def subject
  @subject
end

Instance Method Details

#==(other) ⇒ Object



28
29
30
31
# File 'lib/dispatch-rider/message.rb', line 28

def ==(other)
  return false unless other.respond_to? :attributes
  attributes == other.attributes
end

#as_jsonObject



24
25
26
# File 'lib/dispatch-rider/message.rb', line 24

def as_json(*)
  attributes
end

#attributesObject



20
21
22
# File 'lib/dispatch-rider/message.rb', line 20

def attributes
  { subject: subject, body: body }
end