Sha256: 4f1e0c4d7c7e6ae08a894b75ad92afa597f4669475bd7ee50794d0f58157e8cf

Contents?: true

Size: 1.25 KB

Versions: 2

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

2 entries across 2 versions & 1 rubygems

Version Path
active_event_store-0.2.0 lib/active_event_store/engine.rb
active_event_store-0.1.0 lib/active_event_store/engine.rb