Class: EventStoreClient::Mapper::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/event_store_client/mapper/default.rb

Instance Method Summary collapse

Constructor Details

#initialize(config:, serializer: Serializer::Json) ⇒ Default

Returns a new instance of Default.

Parameters:



13
14
15
16
# File 'lib/event_store_client/mapper/default.rb', line 13

def initialize(config:, serializer: Serializer::Json)
  @serializer = serializer
  @config = config
end

Instance Method Details

#deserialize(event_or_raw_event) ⇒ Object

Parameters:

  • event_or_raw_event (EventStoreClient::DeserializedEvent, EventStore::Client::Streams::ReadResp::ReadEvent::RecordedEvent, EventStore::Client::PersistentSubscriptions::ReadResp::ReadEvent::RecordedEvent)


26
27
28
29
30
31
32
# File 'lib/event_store_client/mapper/default.rb', line 26

def deserialize(event_or_raw_event, **)
  return event_or_raw_event if event_or_raw_event.is_a?(EventStoreClient::DeserializedEvent)

  Serializer::EventDeserializer.call(
    event_or_raw_event, config: config, serializer: serializer
  )
end

#serialize(event) ⇒ EventStoreClient::SerializedEvent



20
21
22
# File 'lib/event_store_client/mapper/default.rb', line 20

def serialize(event)
  Serializer::EventSerializer.call(event, serializer: serializer, config: config)
end