Class: ActionController::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/multitenant-mysql/action_controller_extension.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.set_current_tenant(tenant_method) ⇒ Object

Raises:

  • (InvalidTenantError)


4
5
6
7
8
9
10
11
12
# File 'lib/multitenant-mysql/action_controller_extension.rb', line 4

def self.set_current_tenant(tenant_method)
  raise InvalidTenantError.new('Multitenant::Mysql: you should provide tenant method') unless tenant_method
  @@tenant_method = tenant_method

  before_filter :establish_tenant_connection
  def establish_tenant_connection
    Multitenant::Mysql::ConnectionSwitcher.new(self, @@tenant_method).execute
  end
end

.set_current_tenant_by_subdomainObject



14
15
16
17
18
19
20
# File 'lib/multitenant-mysql/action_controller_extension.rb', line 14

def self.set_current_tenant_by_subdomain
  before_filter :establish_tenant_connection_by_subdomain
  def establish_tenant_connection_by_subdomain
    tenant_name = request.subdomain
    Multitenant::Mysql::ConnectionSwitcher.set_tenant(tenant_name)
  end
end

Instance Method Details

#establish_tenant_connectionObject



9
10
11
# File 'lib/multitenant-mysql/action_controller_extension.rb', line 9

def establish_tenant_connection
  Multitenant::Mysql::ConnectionSwitcher.new(self, @@tenant_method).execute
end

#establish_tenant_connection_by_subdomainObject



16
17
18
19
# File 'lib/multitenant-mysql/action_controller_extension.rb', line 16

def establish_tenant_connection_by_subdomain
  tenant_name = request.subdomain
  Multitenant::Mysql::ConnectionSwitcher.set_tenant(tenant_name)
end