Class: Multitenant::Mysql::ConnectionSwitcher
- Inherits:
-
Object
- Object
- Multitenant::Mysql::ConnectionSwitcher
- Defined in:
- lib/multitenant-mysql/connection_switcher.rb
Instance Attribute Summary collapse
-
#action_controller ⇒ Object
Returns the value of attribute action_controller.
-
#method ⇒ Object
Returns the value of attribute method.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(action_controller, method) ⇒ ConnectionSwitcher
constructor
A new instance of ConnectionSwitcher.
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_controller ⇒ Object
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 |
#method ⇒ Object
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
#execute ⇒ Object
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 |