Class: Akasha::Storage::HttpEventStore::EventSerializer

Inherits:
Object
  • Object
show all
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
# 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 || {}
    event = Akasha::Event.new(ev['eventType'].to_sym, ev['eventId'], , **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