Sha256: bf71bc2564963fc2e9bdbb5f0b64a9221e7a263b6345945993d389373472305e

Contents?: true

Size: 805 Bytes

Versions: 3

Compression:

Stored size: 805 Bytes

Contents

require_relative "base"

module Moleculer
  module Packets
    ##
    # Represents a EVENT packet
    class Event < Base
      attr_reader :event,
                  :data,
                  :broadcast,
                  :groups

      def initialize(data)
        super(data)

        @event     = HashUtil.fetch(data, :event)
        @data      = HashUtil.fetch(data, :data)
        @broadcast = HashUtil.fetch(data, :broadcast)
        @groups    = HashUtil.fetch(data, :groups, [])
        @node      = HashUtil.fetch(data, :node, nil)
      end

      def as_json
        super.merge(
          event:     @event,
          data:      @data,
          broadcast: @broadcast,
          groups:    @groups,
        )
      end

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

Version data entries

3 entries across 3 versions & 1 rubygems

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