module RailsMultitenant::GlobalContextRegistry
Public Instance Methods
delete(symbol)
click to toggle source
delete this global
# File lib/rails_multitenant/global_context_registry.rb, line 24 def delete(symbol) globals.delete(symbol) end
disable_scoped_queries()
click to toggle source
Prefer .with_unscoped_queries to the following two methods. Note: these methods are intended for use in a manner like .with_admin_registry, but in contexts where around semantics are not allowed.
# File lib/rails_multitenant/global_context_registry.rb, line 103 def disable_scoped_queries self[:__use_unscoped_queries] = true end
duplicate_registry()
click to toggle source
Duplicate the registry
# File lib/rails_multitenant/global_context_registry.rb, line 50 def duplicate_registry globals.each_with_object({}) do |(key, value), result| result[key] = value.nil? || value.is_a?(Integer) ? value : value.dup end end
enable_scoped_queries()
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 107 def enable_scoped_queries self[:__use_unscoped_queries] = nil end
fetch(symbol) { || ... }
click to toggle source
Pass with a generator block for the value
# File lib/rails_multitenant/global_context_registry.rb, line 29 def fetch(symbol) result = globals[symbol] unless result result = yield globals[symbol] = result end result end
get(symbol)
click to toggle source
get the global identified by the symbol
# File lib/rails_multitenant/global_context_registry.rb, line 39 def get(symbol) globals[symbol] end
Also aliased as: []
merge!(values)
click to toggle source
merge the given values into the registry
# File lib/rails_multitenant/global_context_registry.rb, line 45 def merge!(values) globals.merge!(values) end
new_registry(registry = {})
click to toggle source
Set a new, by default empty registry, returning the previous one.
# File lib/rails_multitenant/global_context_registry.rb, line 77 def new_registry(registry = {}) priors = globals self.globals = registry priors end
replace_registry(registry)
click to toggle source
Replace the registry with one you previously took away with .new_registry
# File lib/rails_multitenant/global_context_registry.rb, line 84 def replace_registry(registry) self.globals = registry end
set(symbol, value)
click to toggle source
Set this global
# File lib/rails_multitenant/global_context_registry.rb, line 18 def set(symbol, value) globals[symbol] = value end
Also aliased as: []=
use_unscoped_queries?()
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 95 def use_unscoped_queries? self[:__use_unscoped_queries] == true end
with_isolated_registry(registry = {}) { || ... }
click to toggle source
Run a block of code with an the given registry
# File lib/rails_multitenant/global_context_registry.rb, line 57 def with_isolated_registry(registry = {}) prior_globals = new_registry(registry) yield ensure self.globals = prior_globals end
with_merged_registry(values = {}) { || ... }
click to toggle source
Run a block of code with the given values merged into the current registry
# File lib/rails_multitenant/global_context_registry.rb, line 65 def with_merged_registry(values = {}) prior_globals = new_registry(globals.merge(values)) yield ensure self.globals = prior_globals end
with_unscoped_queries() { || ... }
click to toggle source
Run a block of code that disregards scoping during read queries
# File lib/rails_multitenant/global_context_registry.rb, line 89 def with_unscoped_queries with_merged_registry(__use_unscoped_queries: true) do yield end end
Private Instance Methods
add_dependency(parent, dependent)
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 115 def add_dependency(parent, dependent) (@dependencies[parent] ||= []) << dependent end
dependencies_for(klass)
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 119 def dependencies_for(klass) @dependencies[klass] || [] end
globals()
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 123 def globals registry = Thread.current[:global_context_registry] unless registry registry = {} Thread.current[:global_context_registry] = registry end registry end
globals=(value)
click to toggle source
# File lib/rails_multitenant/global_context_registry.rb, line 132 def globals=(value) Thread.current[:global_context_registry] = value end