Sha256: 0726541fb882a2ffb9ee30d5cab18ca5c09f466cd8a3f75b030a0797b68d36cd

Contents?: true

Size: 940 Bytes

Versions: 5

Compression:

Stored size: 940 Bytes

Contents

require_relative 'message/parser'
require_relative 'message/validations'

module SubZero
  class Message
    include Parser
    include Validations

    attr_accessor :type,
                  :subtype,
                  :rid,
                  :verb,
                  :status,
                  :payload,
                  :options

    def initialize args = {}
      @type, @subtype = args.values_at(:type, :subtype)
      @rid            = args[:rid] || SecureRandom.uuid
      @verb, @status  = args.values_at(:verb, :status)
      @payload        = args[:payload] || {}
      @options        = args[:options] || {}
    end

    alias :sid          :subtype
    alias :routing_info :options

    def heartbeat?
      verb == 'PONG'
    end

    def request?
      status.blank?
    end

    def response?
      not request?
    end

    def success?
      status == 'OK'
    end

    def error?
      status == 'NOK'
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
sub_zero-0.0.9 lib/sub_zero/message.rb
sub_zero-0.0.8 lib/sub_zero/message.rb
sub_zero-0.0.7 lib/sub_zero/message.rb
sub_zero-0.0.6 lib/sub_zero/message.rb
sub_zero-0.0.5 lib/sub_zero/message.rb