class RubyEventStore::Record

Constants

StringsRequired

Attributes

data[R]
event_id[R]
event_type[R]
metadata[R]
timestamp[R]
valid_at[R]

Public Class Methods

new(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:) click to toggle source
# File lib/ruby_event_store/record.rb, line 6
def initialize(event_id:, data:, metadata:, event_type:, timestamp:, valid_at:)
  raise StringsRequired unless [event_id, event_type].all? { |v| v.instance_of?(String) }
  @event_id = event_id
  @data = data
  @metadata = metadata
  @event_type = event_type
  @timestamp = timestamp
  @valid_at = valid_at
  @serialized_records = {}
  freeze
end

Public Instance Methods

==(other) click to toggle source
# File lib/ruby_event_store/record.rb, line 24
def ==(other)
  other.instance_of?(self.class) && other.event_id.eql?(event_id) && other.data.eql?(data) &&
    other.metadata.eql?(metadata) && other.event_type.eql?(event_type) && other.timestamp.eql?(timestamp) &&
    other.valid_at.eql?(valid_at)
end
Also aliased as: eql?
eql?(other)
Alias for: ==
hash() click to toggle source
# File lib/ruby_event_store/record.rb, line 20
def hash
  [event_id, data, metadata, event_type, timestamp, valid_at].hash ^ self.class.hash
end
serialize(serializer) click to toggle source
# File lib/ruby_event_store/record.rb, line 41
def serialize(serializer)
  @serialized_records[serializer] ||=
    SerializedRecord.new(
      event_id: event_id,
      event_type: event_type,
      data: serializer.dump(data),
      metadata: serializer.dump(metadata),
      timestamp: timestamp.iso8601(TIMESTAMP_PRECISION),
      valid_at: valid_at.iso8601(TIMESTAMP_PRECISION)
    )
end
to_h() click to toggle source
# File lib/ruby_event_store/record.rb, line 30
def to_h
  {
    event_id: event_id,
    data: data,
    metadata: metadata,
    event_type: event_type,
    timestamp: timestamp,
    valid_at: valid_at
  }
end