Sha256: 4c46c638d490420cdc90d754f5fc8eabf270d9e9b83277a052fa81c27b826b32

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 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_routes!
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
messaging-3.5.5 lib/messaging/rails/railtie.rb
messaging-3.5.4 lib/messaging/rails/railtie.rb
messaging-3.5.3 lib/messaging/rails/railtie.rb
messaging-3.5.2 lib/messaging/rails/railtie.rb
messaging-3.5.1 lib/messaging/rails/railtie.rb
messaging-3.4.3 lib/messaging/rails/railtie.rb
messaging-3.4.2 lib/messaging/rails/railtie.rb