Class: ActiveRecordHostPool::ConnectionProxy

Inherits:
Delegator
  • Object
show all
Defined in:
lib/active_record_host_pool/connection_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(cx, database) ⇒ ConnectionProxy

Returns a new instance of ConnectionProxy.



9
10
11
12
13
# File 'lib/active_record_host_pool/connection_proxy.rb', line 9

def initialize(cx, database)
  super(cx)
  @cx = cx
  @database = database
end

Instance Method Details

#__getobj__Object



15
16
17
18
# File 'lib/active_record_host_pool/connection_proxy.rb', line 15

def __getobj__
  @cx._host_pool_current_database = @database
  @cx
end

#__setobj__(cx) ⇒ Object



20
21
22
# File 'lib/active_record_host_pool/connection_proxy.rb', line 20

def __setobj__(cx)
  @cx = cx
end

#classObject

this is bad. I know. but it allows folks who class_eval on connection.class to do so



29
30
31
# File 'lib/active_record_host_pool/connection_proxy.rb', line 29

def class
  @cx.class
end

#expects(*args) ⇒ Object



33
34
35
# File 'lib/active_record_host_pool/connection_proxy.rb', line 33

def expects(*args)
  @cx.send(:expects, *args)
end

#private_methods(all = true) ⇒ Object



42
43
44
# File 'lib/active_record_host_pool/connection_proxy.rb', line 42

def private_methods(all = true)
  __getobj__.private_methods(all) | super
end

#respond_to_missing?(name, include_private) ⇒ Boolean

Override Delegator#respond_to_missing? to allow private methods to be accessed without warning

Returns:

  • (Boolean)


38
39
40
# File 'lib/active_record_host_pool/connection_proxy.rb', line 38

def respond_to_missing?(name, include_private)
  __getobj__.respond_to?(name, include_private)
end

#send(symbol, *args, &blk) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/active_record_host_pool/connection_proxy.rb', line 46

def send(symbol, *args, &blk)
  if respond_to?(symbol, true) && !__getobj__.respond_to?(symbol, true)
    super
  else
    __getobj__.send(symbol, *args, &blk)
  end
end

#unproxiedObject



24
25
26
# File 'lib/active_record_host_pool/connection_proxy.rb', line 24

def unproxied
  @cx
end