Sha256: 65261e6d367b91ac95c64f25e2698f06f77791d20561eaff90f4117b25f9a1c7

Contents?: true

Size: 649 Bytes

Versions: 7

Compression:

Stored size: 649 Bytes

Contents

module DataMapper
  class TransactionBoundaries

    class Rollback < StandardError; end

    def initialize(app, name = :default)
      @app = app
      @name = name.to_sym
    end
  
    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
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rack-datamapper-0.3.3 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.3.2 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.2.6 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.2.5 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.2.4 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.2.3 lib/rack_datamapper/transaction_boundaries.rb
rack-datamapper-0.2.2 lib/rack_datamapper/transaction_boundaries.rb