Type:
Module

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

Instead of polluting the thread locals namespace:

1
Thread.current[:connection_handler]

you define a class that extends this module:

1
2
3
4
5
6
7
module ActiveRecord
  class RuntimeRegistry
    extend ActiveSupport::PerThreadRegistry
 
    attr_accessor :connection_handler
  end
end

and invoke the declared instance accessors as class methods. So

1
ActiveRecord::RuntimeRegistry.connection_handler = connection_handler

sets a connection handler local to the current thread, and

1
ActiveRecord::RuntimeRegistry.connection_handler

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.

instance
  • References/Ruby on Rails/Rails/Classes/ActiveSupport/ActiveSupport::PerThreadRegistry

instance() Instance Public methods

2025-01-10 15:47:30
extended
  • References/Ruby on Rails/Rails/Classes/ActiveSupport/ActiveSupport::PerThreadRegistry

extended(object) Class Public methods

2025-01-10 15:47:30