Ruby on Rails latest stable (v6.1.7.7) - 0 notes

NOTE: This approach has been deprecated for end-user code in favor of {thread_mattr_accessor}[rdoc-ref:Module#thread_mattr_accessor] and friends. Please use that approach instead.

This module is used to encapsulate access to thread local variables.

Instead of polluting the thread locals namespace:


you define a class that extends this module:

module ActiveRecord
  class RuntimeRegistry
    extend ActiveSupport::PerThreadRegistry

    attr_accessor :connection_handler

and invoke the declared instance accessors as class methods. So

ActiveRecord::RuntimeRegistry.connection_handler = connection_handler

sets a connection handler local to the current thread, and


returns a connection handler local to the current thread.

This feature is accomplished by instantiating the class and storing the instance as a thread local keyed by the class name. In the example above a key “ActiveRecord::RuntimeRegistry” is stored in Thread.current. The class methods proxy to said thread local instance.

If the class has an initializer, it must accept no arguments.

Show files where this module is defined (1 file)
Register or log in to add new notes.