class RailsMiddlewareDelegator

RailsMiddlewareDelegator

Used to wrap a reloadable class used as Rails middleware. In development mode with `cache_classes=false`, after each request all autoloaded modules and classes are unloaded. If one of these classes is used as Rails middleware, then it can cause the following error:

A copy of ZZZ has been removed from the module tree but is still active

This is because Rails will hold onto an instance of the class.

Instead of using the middleware class itself, use an instance of the delegator:

Rails.application.config.
  middleware.use RailsMiddlewareDelegator.new('MyMiddlware')

Constants

VERSION

Attributes

initialization_args[R]
klass[R]

Public Class Methods

new(klass) click to toggle source
# File lib/rails_middleware_delegator.rb, line 25
def initialize(klass)
  @klass = klass
end

Public Instance Methods

call(*args) click to toggle source
# File lib/rails_middleware_delegator.rb, line 38
def call(*args)
  klass.constantize.new(*initialization_args).call(*args)
end
class() click to toggle source
# File lib/rails_middleware_delegator.rb, line 29
def class
  klass
end
new(*args) click to toggle source
# File lib/rails_middleware_delegator.rb, line 33
def new(*args)
  @initialization_args = args
  Rails.application.config.cache_classes ? klass.constantize.new(*args) : self
end