Class: RubyEventStore::Record

Inherits:
Data
  • Object
show all
Defined in:
lib/ruby_event_store/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:) ⇒ Record

Returns a new instance of Record.

Raises:



5
6
7
8
9
# File 'lib/ruby_event_store/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) }
  @serialized_records = {}
  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/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/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/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/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/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/record.rb', line 4

def valid_at
  @valid_at
end

Instance Method Details

#serialize(serializer) ⇒ Object



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

def serialize(serializer)
  @serialized_records[serializer] ||= SerializedRecord.new(
    event_id: event_id,
    event_type: event_type,
    data: serializer.dump(data),
    metadata: serializer.dump(),
    timestamp: timestamp.iso8601(TIMESTAMP_PRECISION),
    valid_at: valid_at.iso8601(TIMESTAMP_PRECISION),
  )
end