Module: RailsMultitenant::GlobalContextRegistry::CurrentInstance::ClassMethods
- Includes:
- RegistryDependentOn
- Defined in:
- lib/rails_multitenant/global_context_registry/current_instance.rb
Instance Method Summary
collapse
#global_context_dependent_on, #global_context_mutually_dependent_on
Instance Method Details
#as_current(model) ⇒ Object
55
56
57
58
59
60
61
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 55
def as_current(model)
old_model = current
self.current = model
yield
ensure
self.current = old_model
end
|
#as_current_id(id) ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 47
def as_current_id(id)
old_id = current_id
self.current_id = id
yield
ensure
self.current_id = old_id
end
|
#clear_current!(cleared = nil) ⇒ Object
63
64
65
66
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 63
def clear_current!(cleared = nil)
GlobalContextRegistry.delete(current_instance_registry_obj)
__clear_dependents!(cleared)
end
|
#current ⇒ Object
33
34
35
36
37
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 33
def current
GlobalContextRegistry.fetch(current_instance_registry_obj) do
(current_id ? find(current_id) : nil)
end
end
|
#current! ⇒ Object
43
44
45
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 43
def current!
current || raise("No current #{name} set")
end
|
#current=(object) ⇒ Object
21
22
23
24
25
26
27
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 21
def current=(object)
raise "#{object} is not a #{self}" if object.present? && !object.is_a?(self)
GlobalContextRegistry.set(current_instance_registry_obj, object)
GlobalContextRegistry.set(current_instance_registry_id, object.try(:id))
__clear_dependents!
end
|
#current? ⇒ Boolean
39
40
41
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 39
def current?
!!current
end
|
#current_id ⇒ Object
29
30
31
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 29
def current_id
GlobalContextRegistry.get(current_instance_registry_id)
end
|
#current_id=(id) ⇒ Object
15
16
17
18
19
|
# File 'lib/rails_multitenant/global_context_registry/current_instance.rb', line 15
def current_id=(id)
GlobalContextRegistry.delete(current_instance_registry_obj)
GlobalContextRegistry.set(current_instance_registry_id, id)
__clear_dependents!
end
|