Class: Synapse::EventStore::Mongo::DocumentPerEventStrategy::EventDocument
- Inherits:
-
Serialization::SerializedDomainEventData
- Object
- Serialization::SerializedDomainEventData
- Synapse::EventStore::Mongo::DocumentPerEventStrategy::EventDocument
- Defined in:
- lib/synapse/event_store/mongo/per_event_strategy.rb
Overview
Mongo document that represents a single domain event
Instance Attribute Summary collapse
- #aggregate_id ⇒ Object readonly
- #id ⇒ String readonly
- #sequence_number ⇒ Integer readonly
- #timestamp ⇒ Time readonly
Instance Method Summary collapse
- #from_event(event, type_identifier, serializer) ⇒ EventDocument
- #from_hash(hash) ⇒ EventDocument
- #metadata ⇒ Object
- #payload ⇒ Object
- #to_events(aggregate_id, serializer, upcaster_chain) ⇒ Array
- #to_hash ⇒ Hash
Instance Attribute Details
#aggregate_id ⇒ Object (readonly)
39 40 41 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 39 def aggregate_id @aggregate_id end |
#id ⇒ String (readonly)
33 34 35 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 33 def id @id end |
#sequence_number ⇒ Integer (readonly)
42 43 44 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 42 def sequence_number @sequence_number end |
#timestamp ⇒ Time (readonly)
36 37 38 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 36 def @timestamp end |
Instance Method Details
#from_event(event, type_identifier, serializer) ⇒ EventDocument
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 59 def from_event(event, type_identifier, serializer) serialization_target = String if serializer.can_serialize_to? Hash serialization_target = Hash end = serializer. event, serialization_target serialized_payload = serializer.serialize_payload event, serialization_target @id = event.id @metadata = .content @payload = serialized_payload.content @payload_type = serialized_payload.type.name @payload_revision = serialized_payload.type.revision @timestamp = event. @aggregate_id = event.aggregate_id @aggregate_type = type_identifier @sequence_number = event.sequence_number self end |
#from_hash(hash) ⇒ EventDocument
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 83 def from_hash(hash) hash.symbolize_keys! @id = hash.fetch :_id @metadata = hash.fetch :metadata @payload = hash.fetch :payload @payload_type = hash.fetch :payload_type @payload_revision = hash.fetch :payload_revision @timestamp = hash.fetch :timestamp @aggregate_id = hash.fetch :aggregate_id @aggregate_type = hash.fetch :aggregate_type @sequence_number = hash.fetch :sequence_number self end |
#metadata ⇒ Object
45 46 47 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 45 def Serialization::SerializedMetadata.new @metadata, @metadata.class end |
#payload ⇒ Object
50 51 52 53 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 50 def payload Serialization::SerializedObject.new @payload, @payload.class, Serialization::SerializedType.new(@payload_type, @payload_revision) end |
#to_events(aggregate_id, serializer, upcaster_chain) ⇒ Array
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 116 def to_events(aggregate_id, serializer, upcaster_chain) events = Array.new context = Upcasting::SerializedDomainEventUpcastingContext.new self, aggregate_id, serializer upcast_objects = upcaster_chain.upcast payload, context upcast_objects.each do |upcast_object| upcast_data = Upcasting::UpcastSerializedDomainEventData.new self, aggregate_id, upcast_object builder = Serialization::SerializedDomainEventMessageBuilder.new # Prevent duplicate serialization of metadata if it was accessed during upcasting = context. if .deserialized? builder. = Serialization::DeserializedObject.new .deserialized end builder.from_data upcast_data, serializer events.push builder.build end events end |
#to_hash ⇒ Hash
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/synapse/event_store/mongo/per_event_strategy.rb', line 100 def to_hash { _id: @id, metadata: @metadata, payload: @payload, payload_type: @payload_type, payload_revision: @payload_revision, timestamp: @timestamp, aggregate_id: @aggregate_id, aggregate_type: @aggregate_type, sequence_number: @sequence_number } end |