Class: Omnes::UnstructuredEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/omnes/unstructured_event.rb

Overview

Event with a payload defined at publication time

An instance of it is automatically created on Bus#publish when a name and payload are given.

Examples:

bus = Omnes::Bus.new
bus.register(:foo)
bus.subscribe(:foo) do |event|
  puts event[:bar]
end
bus.publish(:foo, bar: 'bar') # it'll generate an instance of this class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload:, omnes_event_name:) ⇒ UnstructuredEvent

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of UnstructuredEvent.



28
29
30
31
# File 'lib/omnes/unstructured_event.rb', line 28

def initialize(payload:, omnes_event_name:)
  @payload = payload
  @omnes_event_name = omnes_event_name
end

Instance Attribute Details

#omnes_event_nameSymbol (readonly)

Name of the event

Returns:

  • (Symbol)


20
21
22
# File 'lib/omnes/unstructured_event.rb', line 20

def omnes_event_name
  @omnes_event_name
end

#payloadHash (readonly)

Information made available to the matching subscriptions

Returns:

  • (Hash)


25
26
27
# File 'lib/omnes/unstructured_event.rb', line 25

def payload
  @payload
end

Instance Method Details

#[](key) ⇒ Object

Delegates to #payload

Parameters:

  • key (Any)

Returns:

  • Any



38
39
40
# File 'lib/omnes/unstructured_event.rb', line 38

def [](key)
  payload[key]
end