Class: Akasha::Storage::HttpEventStore::EventSerializer
- Inherits:
-
Object
- Object
- Akasha::Storage::HttpEventStore::EventSerializer
- Defined in:
- lib/akasha/storage/http_event_store/event_serializer.rb
Overview
Serializes and deserializes events to and from the format required by the HTTP Eventstore API
Instance Method Summary collapse
Instance Method Details
#deserialize(es_events) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/akasha/storage/http_event_store/event_serializer.rb', line 23 def deserialize(es_events) es_events.map do |ev| = ev['metaData']&.symbolize_keys || {} data = ev['data']&.symbolize_keys || {} revision = ev['eventNumber'] updated_at = Time.iso8601(ev['updated']) if ev.key?('updated') event = Akasha::RecordedEvent.new(ev['eventType'].to_sym, ev['eventId'], revision, updated_at, , **data) event end end |
#serialize(events) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/akasha/storage/http_event_store/event_serializer.rb', line 11 def serialize(events) events.map do |event| base = { 'eventType' => event.name, 'data' => event.data, 'metaData' => event. } base['eventId'] = event.id unless event.id.nil? base end end |