Sha256: a8bdfed978a22a4f1d280659d559bf039d322c1431472a42c617930e828137a6

Contents?: true

Size: 975 Bytes

Versions: 3

Compression:

Stored size: 975 Bytes

Contents

require_relative "base"

module Moleculer
  module Packets
    ##
    # Represents a RES packet
    class Res < Base
      attr_reader :id,
                  :success,
                  :data,
                  :error,
                  :meta,
                  :stream

      def initialize(data)
        super(data)

        @id      = HashUtil.fetch(data, :id)
        @success = HashUtil.fetch(data, :success)
        @data    = HashUtil.fetch(data, :data)
        @error   = HashUtil.fetch(data, :error, nil)
        @meta    = HashUtil.fetch(data, :meta)
        @stream  = HashUtil.fetch(data, :stream, false)
        @node    = HashUtil.fetch(data, :node, nil)
      end

      def topic
        "#{super}.#{@node.id}"
      end

      def as_json
        super.merge(
          id:      @id,
          success: @success,
          data:    @data,
          error:   @error,
          meta:    @meta,
          stream:  @stream,
        )
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moleculer-0.2.0 lib/moleculer/packets/res.rb
moleculer-0.1.1 lib/moleculer/packets/res.rb
moleculer-0.1.0 lib/moleculer/packets/res.rb