Skip to content

Commit a8bdcea

Browse files
committed
Stop overriding #class
ARHP has been overriding `#class` so that `connection.class.class_eval` can work. That makes it _very_ hard to debug ARHP issues because you're never quite sure what object you're working with. I've changed it so that we now raise an exception if you try to call `.class_eval` on the `ConnectionProxy` class but implements a `._class_eval` method that will allow the typical `class_eval` behavior if someone _really_ needs to.
1 parent e901b25 commit a8bdcea

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

lib/active_record_host_pool/connection_proxy.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@
66
# for each call to the connection. upon executing a statement, the connection will switch to that database.
77
module ActiveRecordHostPool
88
class ConnectionProxy < Delegator
9+
class << self
10+
def class_eval
11+
raise "You probably want to call .class_eval on the ActiveRecord connection adapter and not on ActiveRecordHostPool's connection proxy. Use ._class_eval if you _really_ know what you're doing."
12+
end
13+
14+
def _class_eval(...)
15+
method(:class_eval).super_method.call(...)
16+
end
17+
end
18+
919
attr_reader :database
1020
def initialize(cx, database)
1121
super(cx)
@@ -26,11 +36,6 @@ def unproxied
2636
@cx
2737
end
2838

29-
# this is bad. I know. but it allows folks who class_eval on connection.class to do so
30-
def class
31-
@cx.class
32-
end
33-
3439
def expects(*args)
3540
@cx.send(:expects, *args)
3641
end

0 commit comments

Comments
 (0)