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



3
4
5
6
7
8
9
10
11
12
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 3

def self.included(base)
  base.class_eval do
    attr_accessor(:_host_pool_current_database)
    alias_method_chain :execute, :switching
    alias_method_chain :exec_stmt, :switching if respond_to?(:exec_stmt)
    alias_method_chain :drop_database, :no_switching
    alias_method_chain :create_database, :no_switching
    alias_method_chain :disconnect!, :host_pooling
  end
end

Instance Method Details

#create_database_with_no_switching(*args) ⇒ Object



37
38
39
40
41
42
43
44
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 37

def create_database_with_no_switching(*args)
  begin
    @_no_switch = true
    create_database_without_no_switching(*args)
  ensure
    @_no_switch = false
  end
end

#disconnect_with_host_pooling!Object



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

def disconnect_with_host_pooling!
  @_cached_current_database = nil
  disconnect_without_host_pooling!
end

#drop_database_with_no_switching(*args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 28

def drop_database_with_no_switching(*args)
  begin
    @_no_switch = true
    drop_database_without_no_switching(*args)
  ensure
    @_no_switch = false
  end
end

#exec_stmt_with_switching(sql, name, binds, &block) ⇒ Object



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

def exec_stmt_with_switching(sql, name, binds, &block)
  if _host_pool_current_database && ! @_no_switch
    _switch_connection
  end
  exec_stmt_without_switching(sql, name, binds, &block)
end

#execute_with_switching(*args) ⇒ Object



14
15
16
17
18
19
# File 'lib/active_record_host_pool/connection_adapter_mixin.rb', line 14

def execute_with_switching(*args)
  if _host_pool_current_database && ! @_no_switch
    _switch_connection
  end
  execute_without_switching(*args)
end