ruby-pg
ruby-pg copied to clipboard
inheritence issue with pg version >= 1.3.0
Up until pg version 1.2.3 I could inherit from PG::Connection like this:
class PGx::Connection < PG::Connection
def initialize(*args)
....
end
end
and my derived class' initialize() would be called first, as expected. Starting with pg 1.3.0 onward, the derived class' initialize() is not called at all. I tried for a couple of days to get to the bottom of this, without success. Can you steer me in the right direction?
I use ruby 2.7.6
thanks!
You're right, PG::Connection#initialize is no longer called since pg-1.3.
I made a change to PG::Connection which reactivates the call here but I'm not convinced, that this change should be merged. initialize might be called multiple times per call to PG::Connection.new and gets different arguments. initialize is more kind of internal method, not intended to be derived.
Can you please describe more about your use case for deriving PG::Connection?
My use case: I extended pg to provide logging, retrying and reconnecting. Documentation is here: http://www.mockbites.com/articles/tech/pgx
I think it's best to derive PG::Connection.new instead of PG::Connection#initialize. Also note that there are several alias methods: https://github.com/ged/ruby-pg/blob/master/lib/pg/connection.rb#L684-L687