Sha256: 98c0bc448369979703e3e682f251ed192c5480c21f29de65d85e128917e85afa
Contents?: true
Size: 790 Bytes
Versions: 23
Compression:
Stored size: 790 Bytes
Contents
module V1 module Concerns module ControllerBase extend ActiveSupport::Concern # Controller concen that wraps an API with a transaction, and automatically rolls it back # for non-2xx (or 3xx) responses included do around :action do |controller, callee| begin # TODO: Support Sequel as well ActiveRecord::Base.transaction do callee.call res = controller.response # Force a rollback for non 2xx or 3xx responses raise ActiveRecord::Rollback unless res.status >= 200 && res.status < 400 end rescue ActiveRecord::Rollback # No need to do anything, let the responses flow normally end end end end end end
Version data entries
23 entries across 23 versions & 1 rubygems