Class: ActiveRecordHostPool::ConnectionProxy

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cx, database) ⇒ ConnectionProxy

Returns a new instance of ConnectionProxy.



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

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

Instance Attribute Details

#databaseObject (readonly)

Returns the value of attribute database.



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

def database
  @database
end

Class Method Details

.arhp_connection_proxy_class_evalObject



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

def arhp_connection_proxy_class_eval(...)
  method(:class_eval).super_method.call(...)
end

.class_evalObject



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

def class_eval
  raise "You probably want to call .class_eval on the ActiveRecord connection adapter and not on ActiveRecordHostPool's connection proxy. Use .arhp_connection_proxy_class_eval if you _really_ know what you're doing."
end

Instance Method Details

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



60
61
62
63
64
# File 'lib/active_record_host_pool/connection_proxy.rb', line 60

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

#__getobj__Object



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

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

#__setobj__(cx) ⇒ Object



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

def __setobj__(cx)
  @cx = cx
end

#expects(*args) ⇒ Object



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

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

#hashObject



68
69
70
# File 'lib/active_record_host_pool/connection_proxy.rb', line 68

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

#private_methods(all = true) ⇒ Object



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

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)


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

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

#send(symbol) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/active_record_host_pool/connection_proxy.rb', line 52

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

#unproxiedObject



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

def unproxied
  @cx
end