Sha256: 4c34f3b5fb1723dea175cec808a99d72918303d203515295ee1d6aab101c795e

Contents?: true

Size: 933 Bytes

Versions: 20

Compression:

Stored size: 933 Bytes

Contents

# This class represents a message. All other objects dela with passing around instances of this class.
# A message must have a subject and a body. The subject represents the handlers name and the body represents
# the payload of the process method in the handler.
# When messages are stored in the queues, they are serialized.
module DispatchRider
  class Message
    include ActiveModel::Validations

    attr_accessor :subject, :body

    validates :subject, :presence => true

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

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

    def as_json(*)
      attributes
    end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
dispatch-rider-2.1.0 lib/dispatch-rider/message.rb
dispatch-rider-2.0.0 lib/dispatch-rider/message.rb
dispatch-rider-1.9.0 lib/dispatch-rider/message.rb
dispatch-rider-1.8.6 lib/dispatch-rider/message.rb
dispatch-rider-1.8.5 lib/dispatch-rider/message.rb
dispatch-rider-1.8.4 lib/dispatch-rider/message.rb
dispatch-rider-1.8.3 lib/dispatch-rider/message.rb
dispatch-rider-1.8.2 lib/dispatch-rider/message.rb
dispatch-rider-1.8.1 lib/dispatch-rider/message.rb
dispatch-rider-1.8.0 lib/dispatch-rider/message.rb
dispatch-rider-1.7.2 lib/dispatch-rider/message.rb
dispatch-rider-1.7.1 lib/dispatch-rider/message.rb
dispatch-rider-1.7.0 lib/dispatch-rider/message.rb
dispatch-rider-1.6.2 lib/dispatch-rider/message.rb
dispatch-rider-1.6.1 lib/dispatch-rider/message.rb
dispatch-rider-1.6.0 lib/dispatch-rider/message.rb
dispatch-rider-1.5.3 lib/dispatch-rider/message.rb
dispatch-rider-1.5.2 lib/dispatch-rider/message.rb
dispatch-rider-1.5.1 lib/dispatch-rider/message.rb
dispatch-rider-1.5.0 lib/dispatch-rider/message.rb