Module: RailsMultitenant::GlobalContextRegistry::CurrentInstance

Extended by:
ActiveSupport::Concern
Defined in:
lib/rails_multitenant/global_context_registry/current_instance.rb

Overview

This module allows you to have a current, thread-local instance of a class. This module assumes that you are mixing into a Rails model, and separately stores and id in thread local storage for lazy loading.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#as_currentObject



97
98
99
100
101
102
103
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 97

def as_current
  old_id = self.class.current_id
  self.class.current = self
  yield
ensure
  self.class.current_id = old_id
end

#current?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 105

def current?
  id == self.class.current_id
end