Railsアプリで利用しているgem upsertにモンキーパッチをあてたいため、
gems/upsert-2.1.2/lib/upsert/connection/PG_Connection.rbを
config/initializers/monkey_patches/pg_connnection.rbにコピーして
executeメソッドだけ残した下記のプログラムを置きました。
ruby
1class Upsert 2 class Connection 3 # @private 4 class PG_Connection < Connection 5 #include Postgresql 6 7 def execute(sql, params = nil) 8 if params 9 #metal.exec sql, convert_binary(params) 10 else 11 Upsert.logger.debug { %{[upsertb] #{sql}} } 12 metal.exec sql 13 end 14 end 15 16 end 17 end 18end
ちなみに、include Postgresqlの記述があるとエラーになるため、コメントアウトし、
またmetal.exec sql, convert_binary(params)を走らせたくない修正を行いたかったので、ここもコメントアウトしています。
この状態で処理を走らせてみたところメソッドの内容が書き換わっていないのか、
metal.exec sql, convert_binary(params)が実行されてしまいます。
モンキーパッチの作り方を調べても
classが入れ子になっていたり、includeが絡んでる例が見当たらず、よくわかりませんでした。
何が問題なのでしょうか
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/02/01 06:47
2017/02/01 06:54
2017/02/01 07:04
2017/02/01 09:26 編集