How best to use a private method?

In activerecord-7.0.4/lib/active_record/tasks/postgresql_database_tasks.rb there is a run_cmd private method that I would like to use. It is a trivial method that uses psql_env which is also trivial. I’m writing a database dump rails rake task and will also write a database restore rails rake task.

Should I just make copy of the two methods since they are so simple? I could monkey patch (I think is the term) ActiveRecord::Tasks:PostgreSQLDatabaseTasks but I’ve seen others frown upon that.

If you’re not changing any of the code in those methods, you could create a child class of ActiveRecord::Tasks:PostgreSQLDatabaseTasks and call those methods in exposed public methods of your new class instead.

1 Like