Module: Cell::ModelExtensions
- Defined in:
- lib/cell/model_extensions.rb
Defined Under Namespace
Modules: AssociationExtensions, ClassMethods
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Instance Attribute Details
#tenant ⇒ Object
Returns the value of attribute tenant.
42
43
44
|
# File 'lib/cell/model_extensions.rb', line 42
def tenant
@tenant
end
|
Class Method Details
.prepended(cls) ⇒ Object
66
67
68
69
70
71
72
73
|
# File 'lib/cell/model_extensions.rb', line 66
def self.prepended(cls)
class << cls
prepend ClassMethods
end
cls.after_initialize :_assign_tenant
cls.around_save :_activate_tenant
end
|
Instance Method Details
#_activate_tenant(&block) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/cell/model_extensions.rb', line 50
def _activate_tenant(&block)
if tenant && tenant != ::Cell::Model.current
tenant.use(&block)
else
yield
end
end
|
#_assign_tenant ⇒ Object
44
45
46
47
48
|
# File 'lib/cell/model_extensions.rb', line 44
def _assign_tenant
unless self.class.global_model?
@tenant = Cell::Model.current
end
end
|
#run_validations! ⇒ Object
undocumented, but makes sure validations are ran in the context of the object’s tenant, e.g., uniqueness.
60
61
62
63
64
|
# File 'lib/cell/model_extensions.rb', line 60
def run_validations!
_activate_tenant do
super
end
end
|