グレープ API がありますが、リクエストを行うたびにアクティブ レコード トランザクションでラップできるかどうか疑問に思っています。
トランザクションを行うアクティブなレコードでは、次のようなことができます。
ActiveRecord::Base.transaction do
# do select
# do update
# do insert
end
グレープ API にラップするにはどうすればよいですか?
私の知る限り、Grape API ではbeforeメソッドとafterメソッドを実装できます。
class API < Grape::API
before do
# ????? Need to implement code here to begin active record transaction
# this suppose to begin active record transaction
end
after do
# ????? Need to implement code here to end active record transaction
# this suppose to end active record transaction
end
end