Sha256: 6852d878c8faf80d9689f07970077503dcbb010accb62f9a2d9b43f30571ef75

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

require "rails/engine"

module ActiveEventStore
  class Engine < ::Rails::Engine
    config.active_event_store = ActiveEventStore.config

    # Use before configuration hook to check for ActiveJob presence
    ActiveSupport.on_load(:before_configuration) do
      next warn "Active Job is not loaded. Active Event Store asynchrounous subscriptions won't worke" unless defined?(::ActiveJob)

      require "active_event_store/subscriber_job"
      require "active_event_store/rspec/have_enqueued_async_subscriber_for" if defined?(::RSpec::Matchers)
    end

    config.to_prepare do
      # See https://railseventstore.org/docs/subscribe/#scheduling-async-handlers-after-commit
      ActiveEventStore.event_store = RailsEventStore::Client.new(
        dispatcher: RubyEventStore::ComposedDispatcher.new(
          RailsEventStore::AfterCommitAsyncDispatcher.new(scheduler: RailsEventStore::ActiveJobScheduler.new),
          RubyEventStore::Dispatcher.new
        ),
        repository: ActiveEventStore.config.repository,
        mapper: ActiveEventStore::Mapper.new(mapping: ActiveEventStore.mapping),
        **ActiveEventStore.config.store_options
      )

      ActiveSupport.run_load_hooks(:active_event_store, ActiveEventStore)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_event_store-0.2.1 lib/active_event_store/engine.rb