Class: Comable::Tenant

Inherits:
ActiveRecord::Base
  • Object
show all
Extended by:
FriendlyId
Defined in:
app/models/comable/tenant.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_request(request) ⇒ Tenant

Returns The tenant instance to switch.

Returns:

  • (Tenant)

    The tenant instance to switch



19
20
21
22
23
24
# File 'app/models/comable/tenant.rb', line 19

def from_request(request)
  tenant = find_by(domain: request.domain) if request.domain.present?
  tenant ||= find_by(name: request.subdomains.first)
  tenant ||= new
  tenant
end

Instance Method Details

#createObject



35
36
37
# File 'app/models/comable/tenant.rb', line 35

def create
  ::Apartment::Tenant.create(name)
end

#display_nameObject



31
32
33
# File 'app/models/comable/tenant.rb', line 31

def display_name
  store.try(:name) || name
end

#dropObject



39
40
41
# File 'app/models/comable/tenant.rb', line 39

def drop
  ::Apartment::Tenant.drop(name)
end

#name=(name) ⇒ Object



27
28
29
# File 'app/models/comable/tenant.rb', line 27

def name=(name)
  super name.try(:parameterize)
end

#reset!Object



55
56
57
# File 'app/models/comable/tenant.rb', line 55

def reset!
  ::Apartment::Tenant.switch!
end

#switchObject



43
44
45
# File 'app/models/comable/tenant.rb', line 43

def switch
  ::Apartment::Tenant.switch(name) { yield }
end

#switch!Object



47
48
49
50
51
52
53
# File 'app/models/comable/tenant.rb', line 47

def switch!
  if name
    ::Apartment::Tenant.switch!(name)
  else
    reset!
  end
end