Sha256: 030490a2717f59cc0b54d6abf7d185b5a563f22dc84fa001a9c09ee4fe475768

Contents?: true

Size: 827 Bytes

Versions: 2

Compression:

Stored size: 827 Bytes

Contents

require "rails"

module NATS
  class Rails < ::Rails::Engine
    # This class is used to free resources managed by Rails (e.g. database connections)
    # that were implicitly acquired in subscription callbacks
    # Implementation is based on https://github.com/sidekiq/sidekiq/blob/5e1a77a6d03193dd977fbfe8961ab78df91bb392/lib/sidekiq/rails.rb
    class Reloader
      def initialize(app = ::Rails.application)
        @app = app
      end

      def call
        params = (::Rails::VERSION::STRING >= "7.1") ? {source: "gem.nats"} : {}
        @app.reloader.wrap(**params) do
          yield
        end
      end

      def inspect
        "#<NATS::Rails::Reloader @app=#{@app.class.name}>"
      end
    end

    config.after_initialize do
      NATS::Client.default_reloader = NATS::Rails::Reloader.new
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nats-pure-2.4.0 lib/nats/io/rails.rb
nats-pure-2.3.0 lib/nats/io/rails.rb