Class: Multitenant::Mysql::DB

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

Class Method Summary collapse

Class Method Details

.configsObject



5
6
7
# File 'lib/multitenant-mysql/db.rb', line 5

def configs
  @configs ||= Rails.configuration.database_configuration[Rails.env]
end

.configs=(configs) ⇒ Object



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

def configs=(configs)
  @configs = configs
end

.connectionObject



19
20
21
# File 'lib/multitenant-mysql/db.rb', line 19

def connection
  ActiveRecord::Base.connection
end

.establish_connection_for(tenant_name) ⇒ Object



13
14
15
16
17
# File 'lib/multitenant-mysql/db.rb', line 13

def establish_connection_for tenant_name
  config = configs
  config['username'] = tenant_name.blank? ? 'root' : tenant_name
  ActiveRecord::Base.establish_connection(config)
end