Class: RubyEventStore::Mappers::Transformation::DomainEvent

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/mappers/transformation/domain_event.rb

Instance Method Summary collapse

Instance Method Details

#dump(event) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_event_store/mappers/transformation/domain_event.rb', line 7

def dump(event)
   = event..dup.to_h
  timestamp = .delete(:timestamp)
  valid_at = .delete(:valid_at)
  Record.new(
    event_id: event.event_id,
    metadata: ,
    data: event.data,
    event_type: event.event_type,
    timestamp: timestamp,
    valid_at: valid_at
  )
end

#load(record) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ruby_event_store/mappers/transformation/domain_event.rb', line 21

def load(record)
  Object
    .const_get(record.event_type)
    .new(
      event_id: record.event_id,
      data: record.data,
      metadata: record..merge(timestamp: record.timestamp, valid_at: record.valid_at)
    )
rescue NameError
  Event.new(
    event_id: record.event_id,
    data: record.data,
    metadata:
      record..merge(
        timestamp: record.timestamp,
        valid_at: record.valid_at,
        event_type: record.event_type
      )
  )
end