Class: Synapse::Serialization::SerializationAwareEventMessage

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
SerializationAware
Defined in:
lib/synapse/serialization/message/serialization_aware_message.rb

Overview

Decorator for an event message that adds serialization awareness

Any serialization that occurs on the metadata or payload of this message will be cached so that if a message is serialized more than once, the serialization process will only occur once.

Direct Known Subclasses

SerializationAwareDomainEventMessage

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializationAware

#serialize_metadata, #serialize_payload

Constructor Details

#initialize(message) ⇒ undefined

Parameters:

  • message (EventMessage)


24
25
26
27
# File 'lib/synapse/serialization/message/serialization_aware_message.rb', line 24

def initialize(message)
  @message = message
  @cache = SerializedObjectCache.new message
end

Class Method Details

.decorate(message) ⇒ SerializationAwareEventMessage

Parameters:

  • message (EventMessage)

Returns:



14
15
16
17
18
19
20
# File 'lib/synapse/serialization/message/serialization_aware_message.rb', line 14

def self.decorate(message)
  if message.is_a? SerializationAware
    return message
  end

  self.new message
end

Instance Method Details

#and_metadata(additional_metadata) ⇒ SerializationAwareEventMessage

Parameters:

  • additional_metadata (Hash)

Returns:

See Also:



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

def ()
  new_message = @message. 
  if new_message.equal? @message
    return self
  end

  self.class.new new_message
end

#with_metadata(replacement_metadata) ⇒ SerializationAwareEventMessage

Parameters:

  • replacement_metadata (Hash)

Returns:

See Also:



44
45
46
47
48
49
50
51
# File 'lib/synapse/serialization/message/serialization_aware_message.rb', line 44

def ()
  new_message = @message. 
  if new_message.equal? @message
    return self
  end

  self.class.new new_message
end