Class: Rack::Transaction
- Inherits:
-
Object
- Object
- Rack::Transaction
- Defined in:
- lib/sequel_transaction/rack/transaction.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(inner, settings) ⇒ Transaction
constructor
A new instance of Transaction.
Constructor Details
#initialize(inner, settings) ⇒ Transaction
Returns a new instance of Transaction.
3 4 5 6 |
# File 'lib/sequel_transaction/rack/transaction.rb', line 3 def initialize(inner, settings) @inner = inner @connection = settings.fetch(:connection) end |
Instance Method Details
#call(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/sequel_transaction/rack/transaction.rb', line 8 def call(env) req = Request.new env if req.get? || req.head? || req. result = @inner.call env else env['transaction.connection'] = @connection @connection.transaction do result = @inner.call env response = Response.new [], result[0] err = env['sinatra.error'] if err || response.client_error? || response.server_error? raise Sequel::Rollback end end end result end |