class DataMapper::TransactionBoundaries

Public Class Methods

new(app, name = :default) click to toggle source
# File lib/rack_datamapper/transaction_boundaries.rb, line 6
def initialize(app, name = :default)
  @app = app
  @name = name.to_sym
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack_datamapper/transaction_boundaries.rb, line 11
def call(env)
  status, headers, response = nil, nil, nil
  begin
    transaction = DataMapper::Transaction.new(DataMapper.repository(@name))
    transaction.commit do
      status, headers, response = @app.call(env)
      raise Rollback if status >= 400 or status < 200
    end
  rescue Rollback 
    # ignore, needed to trigger the rollback on the transaction
  end
  [status, headers, response]
end