Sha256: b7ece7dfdb5bc68b7ed55ea361276ff2d9a9bd67044960a64ac1b38a0711e7d9

Contents?: true

Size: 988 Bytes

Versions: 1

Compression:

Stored size: 988 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(config, data)
        super(config, 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 to_h
        super.merge(
          id:      @id,
          success: @success,
          data:    @data,
          error:   @error,
          meta:    @meta,
          stream:  @stream,
        )
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
moleculer-0.3.0 lib/moleculer/packets/res.rb