Class: Comable::Tenant
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Comable::Tenant
- Extended by:
- FriendlyId
- Defined in:
- app/models/comable/tenant.rb
Class Method Summary collapse
-
.from_request(request) ⇒ Tenant
The tenant instance to switch.
Instance Method Summary collapse
- #create ⇒ Object
- #display_name ⇒ Object
- #drop ⇒ Object
- #name=(name) ⇒ Object
- #reset! ⇒ Object
- #switch ⇒ Object
- #switch! ⇒ Object
Class Method Details
.from_request(request) ⇒ Tenant
Returns 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
#create ⇒ Object
35 36 37 |
# File 'app/models/comable/tenant.rb', line 35 def create ::Apartment::Tenant.create(name) end |
#display_name ⇒ Object
31 32 33 |
# File 'app/models/comable/tenant.rb', line 31 def display_name store.try(:name) || name end |
#drop ⇒ Object
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 |
#switch ⇒ Object
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 |