Module: ActiveRecordHostPool::DatabaseSwitch

Defined in:
lib/active_record_host_pool/connection_adapter_mixin.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 21

def self.included(base)
  base.class_eval do
    attr_reader(:_host_pool_current_database)

    # Patch `raw_execute` instead of `execute` since this commit:
    # https://github.com/rails/rails/commit/f69bbcbc0752ca5d5af327d55922614a26f5c7e9
    case "#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}"
    when "7.1"
      alias_method :raw_execute_without_switching, :raw_execute
      alias_method :raw_execute, :raw_execute_with_switching
    else
      alias_method :execute_without_switching, :execute
      alias_method :execute, :execute_with_switching
    end

    alias_method :drop_database_without_no_switching, :drop_database
    alias_method :drop_database, :drop_database_with_no_switching

    alias_method :create_database_without_no_switching, :create_database
    alias_method :create_database, :create_database_with_no_switching

    alias_method :disconnect_without_host_pooling!, :disconnect!
    alias_method :disconnect!, :disconnect_with_host_pooling!
  end
end

.ruby2_keywordsObject



57
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 57

def self.ruby2_keywords(*); end

Instance Method Details

#_host_pool_current_database=(database) ⇒ Object



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

def _host_pool_current_database=(database)
  @_host_pool_current_database = database
  @config[:database] = _host_pool_current_database
end

#create_database_with_no_switching(*args) ⇒ Object



84
85
86
87
88
89
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 84

def create_database_with_no_switching(*args)
  self._no_switch = true
  create_database_without_no_switching(*args)
ensure
  self._no_switch = false
end

#disconnect_with_host_pooling!Object



91
92
93
94
95
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 91

def disconnect_with_host_pooling!
  @_cached_current_database = nil
  @_cached_connection_object_id = nil
  disconnect_without_host_pooling!
end

#drop_database_with_no_switching(*args) ⇒ Object



77
78
79
80
81
82
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 77

def drop_database_with_no_switching(*args)
  self._no_switch = true
  drop_database_without_no_switching(*args)
ensure
  self._no_switch = false
end

#initializeObject



47
48
49
50
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 47

def initialize(*)
  @_cached_current_database = nil
  super
end