Sha256: fda4dd3a7dfbe8b6704fced5f8daeae4b31dab3ff7d49eefdafcbb06c2b401b8

Contents?: true

Size: 942 Bytes

Versions: 44

Compression:

Stored size: 942 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 to_json
      attributes.to_json
    end

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

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
dispatch-rider-1.4.2 lib/dispatch-rider/message.rb
dispatch-rider-1.4.0 lib/dispatch-rider/message.rb
dispatch-rider-1.3.6 lib/dispatch-rider/message.rb
dispatch-rider-1.3.5 lib/dispatch-rider/message.rb
dispatch-rider-1.3.4 lib/dispatch-rider/message.rb
dispatch-rider-1.3.3 lib/dispatch-rider/message.rb
dispatch-rider-1.3.2 lib/dispatch-rider/message.rb
dispatch-rider-1.3.1 lib/dispatch-rider/message.rb
dispatch-rider-1.3.0 lib/dispatch-rider/message.rb
dispatch-rider-1.2.11 lib/dispatch-rider/message.rb
dispatch-rider-1.2.10 lib/dispatch-rider/message.rb
dispatch-rider-1.2.9 lib/dispatch-rider/message.rb
dispatch-rider-1.2.8 lib/dispatch-rider/message.rb
dispatch-rider-1.2.7 lib/dispatch-rider/message.rb
dispatch-rider-1.2.6 lib/dispatch-rider/message.rb
dispatch-rider-1.2.5 lib/dispatch-rider/message.rb
dispatch-rider-1.2.4 lib/dispatch-rider/message.rb
dispatch-rider-1.2.3 lib/dispatch-rider/message.rb
dispatch-rider-1.2.2 lib/dispatch-rider/message.rb
dispatch-rider-1.2.1 lib/dispatch-rider/message.rb