Class: Synapse::Domain::EventMessage

Inherits:
Message
  • Object
show all
Defined in:
lib/synapse/domain/message.rb

Overview

Represents the occurance of an event in the application that may be of some importance to another component of the application. It contains the relevant data for other components to act upon.

Direct Known Subclasses

DomainEventMessage

Instance Attribute Summary collapse

Attributes inherited from Message

#id, #metadata, #payload

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Message

#and_metadata, build, #payload_type, #with_metadata

Constructor Details

#initialize(id, metadata, payload, timestamp) ⇒ undefined

Parameters:

  • id (String)
  • metadata (Hash)
  • payload (Object)
  • timestamp (Time)


16
17
18
19
# File 'lib/synapse/domain/message.rb', line 16

def initialize(id, , payload, timestamp)
  super id, , payload
  @timestamp = timestamp
end

Instance Attribute Details

#timestampTime (readonly)

The timestamp of when the event was reported

Returns:

  • (Time)


9
10
11
# File 'lib/synapse/domain/message.rb', line 9

def timestamp
  @timestamp
end

Class Method Details

.as_message(event) ⇒ EventMessage

Creates an event message using the given event object

If the given object is an event message, it will be returned unchanged.

Parameters:

  • event (Object)

Returns:



32
33
34
35
36
37
38
39
40
# File 'lib/synapse/domain/message.rb', line 32

def self.as_message(event)
  unless event.is_a? EventMessage
    event = self.build do |builder|
      builder.payload = event
    end
  end

  event
end

.builderClass

Returns:

  • (Class)


22
23
24
# File 'lib/synapse/domain/message.rb', line 22

def self.builder
  EventMessageBuilder
end