Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion apps/rails_application/config/initializers/rails_event_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,23 @@
require "arkency/command_bus"

require_relative "../../lib/configuration"
require_relative "../../lib/transformations/refund_to_return_event_mapper"

Rails.configuration.to_prepare do
Rails.configuration.event_store = Infra::EventStore.main
mapper = RubyEventStore::Mappers::PipelineMapper.new(
RubyEventStore::Mappers::Pipeline.new(
Infra::EventStore.preserve_types,
Transformations::RefundToReturnEventMapper.new(
'Ordering::DraftRefundCreated' => 'Ordering::DraftReturnCreated',
'Ordering::ItemAddedToRefund' => 'Ordering::ItemAddedToReturn',
'Ordering::ItemRemovedFromRefund' => 'Ordering::ItemRemovedFromReturn'
),
RubyEventStore::Mappers::Transformation::SymbolizeMetadataKeys.new,
to_domain_event: RubyEventStore::Mappers::Transformation::DomainEvent.new
)
)

Rails.configuration.event_store = Infra::EventStore.main(mapper: mapper)
Rails.configuration.command_bus = Arkency::CommandBus.new

Configuration.new.call(Rails.configuration.event_store, Rails.configuration.command_bus)
Expand Down
35 changes: 12 additions & 23 deletions infra/lib/infra/event_store.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,19 @@
module Infra
class EventStore < SimpleDelegator
def self.main
require_relative "../../../apps/rails_application/lib/transformations/refund_to_return_event_mapper" rescue nil
def self.main(mapper: nil)
mapper ||= default_mapper
client = RailsEventStore::JSONClient.new(mapper: mapper)
new(client)
end

begin
mapper = RubyEventStore::Mappers::PipelineMapper.new(
RubyEventStore::Mappers::Pipeline.new(
preserve_types,
Transformations::RefundToReturnEventMapper.new(
'Ordering::DraftRefundCreated' => 'Ordering::DraftReturnCreated',
'Ordering::ItemAddedToRefund' => 'Ordering::ItemAddedToReturn',
'Ordering::ItemRemovedFromRefund' => 'Ordering::ItemRemovedFromReturn'
),
RubyEventStore::Mappers::Transformation::SymbolizeMetadataKeys.new,
to_domain_event: RubyEventStore::Mappers::Transformation::DomainEvent.new
)
def self.default_mapper
RubyEventStore::Mappers::PipelineMapper.new(
RubyEventStore::Mappers::Pipeline.new(
preserve_types,
RubyEventStore::Mappers::Transformation::SymbolizeMetadataKeys.new,
to_domain_event: RubyEventStore::Mappers::Transformation::DomainEvent.new
)
client = RailsEventStore::JSONClient.new(mapper: mapper)
rescue => e
puts "Mapper creation failed: #{e.message}"
client = RailsEventStore::JSONClient.new
end

new(client)
)
end

def self.in_memory
Expand Down Expand Up @@ -53,8 +44,6 @@ def link_event_to_stream(event, stream, expected_version: :any)
)
end

private

def self.preserve_types
preserve_types = RubyEventStore::Mappers::Transformation::PreserveTypes.new

Expand Down
Loading