Module: SlavePools::Hijack

Defined in:
lib/slave_pools/hijack.rb

Overview

The hijack is added to ActiveRecord::Base but only applies to its descendants. The Base.connection is left in place.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



5
6
7
8
9
10
# File 'lib/slave_pools/hijack.rb', line 5

def self.extended(base)
  # hijack models that have already been loaded
  base.send(:descendants).each do |child|
    child.hijack_connection
  end
end

Instance Method Details

#hijack_connectionObject



18
19
20
21
22
# File 'lib/slave_pools/hijack.rb', line 18

def hijack_connection
  class << self
    alias_method :connection, :connection_proxy
  end
end

#inherited(child) ⇒ Object

hijack models that get loaded later



13
14
15
16
# File 'lib/slave_pools/hijack.rb', line 13

def inherited(child)
  super
  child.hijack_connection
end