class Multiplicity::Tenant

Constants

UnknownTenantError

Public Class Methods

column_names() click to toggle source
# File lib/multiplicity/tenant.rb, line 24
def column_names
  attribute_set.map(&:name)
end
current() click to toggle source
# File lib/multiplicity/tenant.rb, line 28
def current
  Thread.current[:multiplicity_tenant]
end
current=(value) click to toggle source
# File lib/multiplicity/tenant.rb, line 32
def current=(value)
  Thread.current[:multiplicity_tenant] = value
end
current_id() click to toggle source
# File lib/multiplicity/tenant.rb, line 36
def current_id
  current && current.id
end
find_by(field, value) click to toggle source
# File lib/multiplicity/tenant.rb, line 52
def find_by(field, value)
  return current if current && current.send(field) == value

  record = Multiplicity.adapter.find_by(field, value)

  self.current = nil
  self.current = new(record) if record
end
find_by!(field, value) click to toggle source
# File lib/multiplicity/tenant.rb, line 61
def find_by!(field, value)
  find_by(field, value) or raise UnknownTenantError, "Unknown Tenant #{field}: #{value}"
end
load(subdomain) click to toggle source
# File lib/multiplicity/tenant.rb, line 48
def load(subdomain)
  find_by :subdomain, subdomain
end
use_tenant(subdomain) { || ... } click to toggle source
# File lib/multiplicity/tenant.rb, line 40
def use_tenant(subdomain)
  previous = Tenant.current
  find_by :subdomain, subdomain
  yield
ensure
  self.current = previous
end

Public Instance Methods

archived?() click to toggle source
# File lib/multiplicity/tenant.rb, line 15
def archived?
  !!deleted_at
end
uri(domain = Multiplicity.domain) click to toggle source
# File lib/multiplicity/tenant.rb, line 19
def uri(domain = Multiplicity.domain)
  URI("https://#{ subdomain }.#{ domain }")
end