Sha256: 69d176e8d9de1d8e8f843b73f96b2e75efaaa726f8d71379dc2314ad08f8aecf

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'rails/railtie'
require 'messaging/middleware/after_active_record_transaction'
require 'messaging/middleware/rails_wrapper'

module Messaging
  module Rails
    class Railtie < ::Rails::Railtie
      config.after_initialize do
        # Add the wrapper before any middlewares that may have been added by the initializer
        # in the Rails app.
        Messaging.config.consumer.middlewares.prepend(Middleware::RailsWrapper.new(::Rails.application))

        # Run dispatchers after the current transaction has commited
        Messaging.config.dispatcher.middlewares.prepend(Middleware::AfterActiveRecordTransaction)

        # Eager load handlers for development mode to define consumers.
        # This is needed as long as we use old style handlers that uses "listen_on"
        # When we only use routing we don't need to eager load.
        #
        # Uses require_dependency as normal eager_load with Rails breaks code reloading.
        next unless ::Rails.env.development?

        Dir.glob("#{::Rails.root}/app/models/*.rb").each { |h| require_dependency h }
        Dir.glob("#{::Rails.root}/{app,lib}/**/handlers/**/*.rb").each { |h| require_dependency h }
      end

      # As the consumer has a reference to the handler we need to clear that after
      # the class has been unloaded and update the consumer with the reloaded classes.
      initializer 'messaging.add_reloader' do |app|
        app.reloader.after_class_unload do
          Messaging.routes.reload_consumer_subscriptions!
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
messaging-3.4.1 lib/messaging/rails/railtie.rb