Sha256: 15123dc7a0243abe8d045a6efada60174db35177b479e1fbd6a27159e5faa2aa
Contents?: true
Size: 1.37 KB
Versions: 2
Compression:
Stored size: 1.37 KB
Contents
require_relative "../errors/invalid_action_response" require_relative "../support" module Moleculer module Service ## # Represents a service event. class Event # @!attribute [r] name # @return [String] the name of the action # @!attribute [r] service # @return [Moleculer::Service] the service that this event is tied to attr_reader :name, :service ## # @param name [String] the name of the action # @param service [Moleculer::Service] the service to which the action belongs # @param method [Symbol] the method which the event calls when executed # @param options [Hash] the method options # TODO: add ability to group events def initialize(name, service, method, options = {}) @name = name @service = service @method = method @service = service @options = options end ## # Executes the event # @param data [Hash] the event data def execute(data, broker) @service.new(broker).public_send(@method, data) end ## # @return [Moleculer::Node] the node of the service this event is tied to def node @service.node end ## # @return [Hash] a hash representing this event as it would be in JSON def as_json { name: name, } end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
moleculer-0.1.1 | lib/moleculer/service/event.rb |
moleculer-0.1.0 | lib/moleculer/service/event.rb |