Module: Tenancy::Resource::ClassMethods
- Defined in:
- lib/tenancy/resource.rb
Instance Method Summary collapse
- #current ⇒ Object
- #current=(value) ⇒ Object
- #current_id ⇒ Object
- #with(tenant, &block) ⇒ Object (also: #use)
Instance Method Details
#current ⇒ Object
20 21 22 |
# File 'lib/tenancy/resource.rb', line 20 def current RequestStore.store[:"#{name}.current"] end |
#current=(value) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/tenancy/resource.rb', line 7 def current=(value) tenant = case value when self value when nil nil else find(value) end RequestStore.store[:"#{name}.current"] = tenant end |
#current_id ⇒ Object
24 25 26 |
# File 'lib/tenancy/resource.rb', line 24 def current_id current.try(:id) end |
#with(tenant, &block) ⇒ Object Also known as: use
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/tenancy/resource.rb', line 28 def with(tenant, &block) raise ArgumentError, "block required" if block.nil? begin old = self.current self.current = tenant block.call ensure self.current = old end end |