Class: Multitenant::Mysql::ConnectionSwitcher

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(action_controller, method) ⇒ ConnectionSwitcher

Returns a new instance of ConnectionSwitcher.



20
21
22
23
# File 'lib/multitenant-mysql/connection_switcher.rb', line 20

def initialize(action_controller, method)
  @action_controller = action_controller
  @method            = method
end

Instance Attribute Details

#action_controllerObject

Returns the value of attribute action_controller.



18
19
20
# File 'lib/multitenant-mysql/connection_switcher.rb', line 18

def action_controller
  @action_controller
end

#methodObject

Returns the value of attribute method.



18
19
20
# File 'lib/multitenant-mysql/connection_switcher.rb', line 18

def method
  @method
end

Class Method Details

.set_tenant(tenant_name) ⇒ Object



25
26
27
28
# File 'lib/multitenant-mysql/connection_switcher.rb', line 25

def self.set_tenant(tenant_name)
  return unless Tenant.exists?(tenant_name)
  DB.establish_connection_for tenant_name
end

Instance Method Details

#executeObject



30
31
32
33
34
# File 'lib/multitenant-mysql/connection_switcher.rb', line 30

def execute
  tenant_name = action_controller.send(method)
  return unless Tenant.exists?(tenant_name)
  DB.establish_connection_for tenant_name
end