Class: Hippo::Tenant

Inherits:
Model
  • Object
show all
Defined in:
lib/hippo/tenant.rb

Overview

Tenant

Constant Summary collapse

PUBLIC_ATTRS =
%w{slug name identifier}

Constants included from Concerns::ApiAttributeAccess

Concerns::ApiAttributeAccess::DEFAULT_BLACKLISTED

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

belongs_to_tenant, scoped_by_tenant?

Methods included from Concerns::ApiAttributeAccess

#_set_attribute_data_from_collection, #set_attribute_data, #setting_attribute_is_allowed?

Class Method Details

.currentObject



43
44
45
# File 'lib/hippo/tenant.rb', line 43

def self.current
    MultiTenant.current_tenant || system
end

.switch(condition) ⇒ Object



54
55
56
# File 'lib/hippo/tenant.rb', line 54

def self.switch(condition)
    MultiTenant.current_tenant = self.find_by(condition)
end

.systemObject



47
48
49
50
51
52
# File 'lib/hippo/tenant.rb', line 47

def self.system
    find_by(slug: 'system') || create!(
        slug: 'system', name: 'system',
        email: '[email protected]', subscription: :admin
    )
end

Instance Method Details

#bootstrap_dataObject



33
34
35
36
37
38
39
40
41
# File 'lib/hippo/tenant.rb', line 33

def bootstrap_data
    as_json(
        only: PUBLIC_ATTRS,
    ).merge(
        bootstrap: system_settings.public_json.merge(
            Hippo::Extensions.tenant_bootstrap_data(self)
        )
    )
end

#domainObject



23
24
25
# File 'lib/hippo/tenant.rb', line 23

def domain
    self.slug + '.' + Hippo.config.website_domain
end

#performObject



27
28
29
30
31
# File 'lib/hippo/tenant.rb', line 27

def perform
    MultiTenant.with(self) do
        yield
    end
end