RailsEventStore/rails_event_store

View on GitHub
ruby_event_store/lib/ruby_event_store/mappers/transformation/event_class_remapper.rb

Summary

Maintainability
A
0 mins
Test Coverage
# frozen_string_literal: true

module RubyEventStore
  module Mappers
    module Transformation
      class EventClassRemapper
        def initialize(class_map)
          @class_map = class_map
        end

        def dump(record)
          record
        end

        def load(record)
          Record.new(
            event_id: record.event_id,
            event_type: class_map[record.event_type] || record.event_type,
            data: record.data,
            metadata: record.metadata,
            timestamp: record.timestamp,
            valid_at: record.valid_at
          )
        end

        private

        attr_reader :class_map
      end
    end
  end
end