Class: ActiveRecordHostPool::ConnectionProxy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cx, database) ⇒ ConnectionProxy

Returns a new instance of ConnectionProxy.



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

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

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



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

def database
  @database
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



56
57
58
59
60
# File 'lib/active_record_host_pool/connection_proxy.rb', line 56

def ==(other)
  self.class == other.class &&
    other.respond_to?(:unproxied) && @cx == other.unproxied &&
    other.respond_to?(:database) && @database == other.database
end

#__getobj__Object



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

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

#__setobj__(cx) ⇒ Object



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

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



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

def class
  @cx.class
end

#expects(*args) ⇒ Object



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

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

#hashObject



64
65
66
# File 'lib/active_record_host_pool/connection_proxy.rb', line 64

def hash
  [self.class, @cx, @database].hash
end

#private_methods(all = true) ⇒ Object



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

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)


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

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

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



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

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



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

def unproxied
  @cx
end