Sha256: c831a885bea7719e99d6ffe0dc21b68ee244b0fe167bf9bf7bbafd178ca2a85b

Contents?: true

Size: 490 Bytes

Versions: 7

Compression:

Stored size: 490 Bytes

Contents

module EventSourcery
  module EventStore
    class EventBuilder
      def initialize(event_type_serializer:)
        @event_type_serializer = event_type_serializer
      end

      def build(event_data)
        type = event_data.fetch(:type)
        klass = event_type_serializer.deserialize(type)
        upcast(klass.new(event_data))
      end

      private

      attr_reader :event_type_serializer

      def upcast(event)
        event.class.upcast(event)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
event_sourcery-0.23.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.22.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.21.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.20.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.19.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.18.0 lib/event_sourcery/event_store/event_builder.rb
event_sourcery-0.17.0 lib/event_sourcery/event_store/event_builder.rb