Class: DataMapper::TransactionBoundaries
- Inherits:
-
Object
- Object
- DataMapper::TransactionBoundaries
- Defined in:
- lib/rack_datamapper/transaction_boundaries.rb
Defined Under Namespace
Classes: Rollback
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, name = :default) ⇒ TransactionBoundaries
constructor
A new instance of TransactionBoundaries.
Constructor Details
#initialize(app, name = :default) ⇒ TransactionBoundaries
Returns a new instance of TransactionBoundaries.
6 7 8 9 |
# File 'lib/rack_datamapper/transaction_boundaries.rb', line 6 def initialize(app, name = :default) @app = app @name = name.to_sym end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# 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 |