Module: PDC::Resource
- Defined in:
- lib/pdc/resource/per_thread_registry.rb,
lib/pdc/resource/path.rb,
lib/pdc/resource/scopes.rb,
lib/pdc/resource/identity.rb,
lib/pdc/resource/relation.rb,
lib/pdc/resource/rest_api.rb,
lib/pdc/resource/attributes.rb,
lib/pdc/resource/associations.rb,
lib/pdc/resource/value_parser.rb,
lib/pdc/resource/relation/query.rb,
lib/pdc/resource/scope_registry.rb,
lib/pdc/resource/attribute_store.rb,
lib/pdc/resource/relation/finder.rb,
lib/pdc/resource/attribute_modifier.rb,
lib/pdc/resource/relation/pagination.rb,
lib/pdc/resource/associations/builder.rb,
lib/pdc/resource/associations/has_many.rb,
lib/pdc/resource/associations/association.rb
Overview
This module is used to encapsulate access to thread local variables.
Instead of polluting the thread locals namespace:
Thread.current[:connection_handler]
you define a class that extends this module:
module ActiveRecord
class RuntimeRegistry
extend ActiveSupport::PerThreadRegistry
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.
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.
Defined Under Namespace
Modules: Associations, AttributeModifier, Attributes, Finder, Identity, Pagination, PerThreadRegistry, Query, RestApi, Scopes Classes: AttributeStore, Path, Relation, ScopeRegistry, ValueParser
Constant Summary collapse
- PAGINATION =
:pagination
- PAGINATION_KEYS =
%i[ resource_count previous_page next_page ].freeze