If you need a global state for a request in Rails, request_store by Steve Klabnik is a great solution.
This gem provides API for RequestStore
, that is similar to ActiveSupport::PerThreadRegistry API.
You define a class that extends this module:
module ActiveRecord
class RuntimeRegistry
extend RequestStoreRegistry
attr_accessor :connection_handler
end
end
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
ActiveRecord::RuntimeRegistry.connection_handler
returns a connection handler local to the current thread.
- Fork it ( https://github.com/[my-github-username]/request_store_registry/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request