class Hippo::Tenant

Tenant

Constants

PUBLIC_ATTRS

Public Class Methods

current() click to toggle source
# File lib/hippo/tenant.rb, line 43
def self.current
    MultiTenant.current_tenant || system
end
switch(condition) click to toggle source
# File lib/hippo/tenant.rb, line 53
def self.switch(condition)
    MultiTenant.current_tenant = self.find_by(condition)
end
system() click to toggle source
# File lib/hippo/tenant.rb, line 47
def self.system
    find_by(slug: 'system') || create!(
        slug: 'system', name: 'system', email: 'contact@argosity.com'
    )
end

Public Instance Methods

bootstrap_data() click to toggle source
# File lib/hippo/tenant.rb, line 33
def bootstrap_data
    as_json(
        only: PUBLIC_ATTRS,
    ).merge(
        bootstrap: SystemSettings.config.public_json.merge(
            Hippo::Extensions.tenant_bootstrap_data(self)
        )
    )
end
domain() click to toggle source
# File lib/hippo/tenant.rb, line 23
def domain
    self.slug + '.' + Hippo.config.website_domain
end
perform() { || ... } click to toggle source
# File lib/hippo/tenant.rb, line 27
def perform
    MultiTenant.with(self) do
        yield
    end
end

Protected Instance Methods

auto_assign_slug() click to toggle source
# File lib/hippo/tenant.rb, line 59
def auto_assign_slug
    5.times do |i|
        if slug.blank?
            newslug = Hippo::Strings.code_identifier(self.name, length: i + 5).downcase
            self.slug = newslug if Tenant.where(slug: newslug).none?
        end
        break if slug.present?
    end
end
downcase_slug() click to toggle source
# File lib/hippo/tenant.rb, line 69
def downcase_slug
    self.slug = self.slug.downcase.gsub(/\W/, '')
end