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:



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

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.



11
12
13
# File 'lib/dispatch-rider/message.rb', line 11

def body
  @body
end

#subjectObject

Returns the value of attribute subject.



11
12
13
# File 'lib/dispatch-rider/message.rb', line 11

def subject
  @subject
end

Instance Method Details

#==(other) ⇒ Object



30
31
32
33
34
# File 'lib/dispatch-rider/message.rb', line 30

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

  attributes == other.attributes
end

#as_jsonObject



26
27
28
# File 'lib/dispatch-rider/message.rb', line 26

def as_json(*)
  attributes
end

#attributesObject



22
23
24
# File 'lib/dispatch-rider/message.rb', line 22

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