Class: RubyEventStore::SerializedRecord

Inherits:
Data
  • Object
show all
Defined in:
lib/ruby_event_store/serialized_record.rb

Constant Summary collapse

StringsRequired =
StringsRequired

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) ⇒ SerializedRecord

Returns a new instance of SerializedRecord.

Raises:



5
6
7
8
# File 'lib/ruby_event_store/serialized_record.rb', line 5

def initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:)
  raise StringsRequired unless [event_id, event_type].all? { |v| v.instance_of?(String) }
  super
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data

Returns:

  • (Object)

    the current value of data



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def data
  @data
end

#event_idObject (readonly)

Returns the value of attribute event_id

Returns:

  • (Object)

    the current value of event_id



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def event_id
  @event_id
end

#event_typeObject (readonly)

Returns the value of attribute event_type

Returns:

  • (Object)

    the current value of event_type



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def event_type
  @event_type
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def 
  @metadata
end

#timestampObject (readonly)

Returns the value of attribute timestamp

Returns:

  • (Object)

    the current value of timestamp



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def timestamp
  @timestamp
end

#valid_atObject (readonly)

Returns the value of attribute valid_at

Returns:

  • (Object)

    the current value of valid_at



4
5
6
# File 'lib/ruby_event_store/serialized_record.rb', line 4

def valid_at
  @valid_at
end

Instance Method Details

#deserialize(serializer) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/ruby_event_store/serialized_record.rb', line 10

def deserialize(serializer)
  Record.new(
    event_id: event_id,
    event_type: event_type,
    data: serializer.load(data),
    metadata: serializer.load(),
    timestamp: Time.iso8601(timestamp),
    valid_at: Time.iso8601(valid_at),
  )
end