Class: Moleculer::Service::Event
- Inherits:
-
Object
- Object
- Moleculer::Service::Event
- Defined in:
- lib/moleculer/service/event.rb
Overview
Represents a service event.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
The name of the action.
-
#service ⇒ Object
readonly
Returns the value of attribute service.
Instance Method Summary collapse
-
#execute(data, broker) ⇒ Object
Executes the event.
-
#initialize(name, service, method, options = {}) ⇒ Event
constructor
TODO: add ability to group events.
-
#node ⇒ Moleculer::Node
The node of the service this event is tied to.
-
#to_h ⇒ Hash
A hash representing this event as it would be in JSON.
Constructor Details
#initialize(name, service, method, options = {}) ⇒ Event
TODO: add ability to group events
20 21 22 23 24 25 26 |
# File 'lib/moleculer/service/event.rb', line 20 def initialize(name, service, method, = {}) @name = name @service = service @method = method @service = service @options = end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns the name of the action.
12 13 14 |
# File 'lib/moleculer/service/event.rb', line 12 def name @name end |
#service ⇒ Object (readonly)
Returns the value of attribute service.
12 |
# File 'lib/moleculer/service/event.rb', line 12 attr_reader :name, :service |
Instance Method Details
#execute(data, broker) ⇒ Object
Executes the event
32 33 34 35 36 |
# File 'lib/moleculer/service/event.rb', line 32 def execute(data, broker) @service.new(broker).public_send(@method, data) rescue StandardError => e broker.config.handle_error(e) end |
#node ⇒ Moleculer::Node
Returns the node of the service this event is tied to.
40 41 42 |
# File 'lib/moleculer/service/event.rb', line 40 def node @service.node end |
#to_h ⇒ Hash
Returns a hash representing this event as it would be in JSON.
46 47 48 49 50 |
# File 'lib/moleculer/service/event.rb', line 46 def to_h { name: name, } end |