Module: MultiTenant::ActsAsTenant::TenantHelpers

Defined in:
lib/multi_tenant/acts_as_tenant.rb

Instance Method Summary collapse

Instance Method Details

#with_each_tenantObject

Loops through each tenant, sets it as current, and yields to any given block. At the end, current is always set back to what it was originally.



127
128
129
130
131
132
133
134
135
# File 'lib/multi_tenant/acts_as_tenant.rb', line 127

def with_each_tenant
  old_tenants = self.current_tenants
  all.each do |tenant|
    self.current_tenant = tenant
    yield if block_given?
  end
ensure
  self.current_tenants = old_tenants
end

#with_tenant(record_or_identifier) ⇒ Object

Sets the given tenant as the current one and yields to a given block. At the end, current is always set back to what it was originally.



141
142
143
144
145
146
147
# File 'lib/multi_tenant/acts_as_tenant.rb', line 141

def with_tenant(record_or_identifier)
  old_tenants = self.current_tenants
  self.current_tenant = record_or_identifier
  yield if block_given?
ensure
  self.current_tenants = old_tenants
end

#with_tenants(records_or_identifiers) ⇒ Object

Sets the given array of tenants as the current one and yields to a given block. At the end, current is always set back to what it was originally.



153
154
155
156
157
158
159
# File 'lib/multi_tenant/acts_as_tenant.rb', line 153

def with_tenants(records_or_identifiers)
  old_tenants = self.current_tenants
  self.current_tenants = records_or_identifiers
  yield if block_given?
ensure
  self.current_tenants = old_tenants
end

#without_tenantObject Also known as: without_tenants

Sets current to nil and yields to the block. At the end, current is always set back to what it was originally.



165
166
167
168
169
170
171
# File 'lib/multi_tenant/acts_as_tenant.rb', line 165

def without_tenant
  old_tenants = self.current_tenants
  self.current_tenant = nil
  yield if block_given?
ensure
  self.current_tenants = old_tenants
end