Module: ActiveRecordHostPool::DatabaseSwitch

Defined in:
lib/active_record_host_pool/connection_adapter_mixin.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#_host_pool_current_databaseObject

Returns the value of attribute _host_pool_current_database.



21
22
23
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 21

def _host_pool_current_database
  @_host_pool_current_database
end

Instance Method Details

#create_databaseObject



57
58
59
60
61
62
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 57

def create_database(...)
  self._no_switch = true
  super
ensure
  self._no_switch = false
end

#disconnect!Object



64
65
66
67
68
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 64

def disconnect!
  @_cached_current_database = nil
  @_cached_connection_object_id = nil
  super
end

#drop_databaseObject



50
51
52
53
54
55
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 50

def drop_database(...)
  self._no_switch = true
  super
ensure
  self._no_switch = false
end

#executeObject



42
43
44
45
46
47
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 42

def execute(...)
  if _host_pool_current_database && !_no_switch
    _switch_connection
  end
  super
end

#initializeObject



22
23
24
25
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 22

def initialize(*)
  @_cached_current_database = nil
  super
end

#raw_executeObject

Patch ‘raw_execute` instead of `execute` since this commit: github.com/rails/rails/commit/f69bbcbc0752ca5d5af327d55922614a26f5c7e9



35
36
37
38
39
40
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 35

def raw_execute(...)
  if _host_pool_current_database && !_no_switch
    _switch_connection
  end
  super
end