Class: UpAndAtThem::Transaction
- Inherits:
-
Object
- Object
- UpAndAtThem::Transaction
- Defined in:
- lib/up_and_at_them.rb
Instance Method Summary collapse
-
#initialize(tasks) ⇒ Transaction
constructor
A new instance of Transaction.
- #run ⇒ Object
Constructor Details
#initialize(tasks) ⇒ Transaction
Returns a new instance of Transaction.
23 24 25 26 27 28 29 30 |
# File 'lib/up_and_at_them.rb', line 23 def initialize(tasks) tasks = Array(tasks) tasks.each do |t| Commit === t or raise TypeError end @tasks = tasks run end |
Instance Method Details
#run ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/up_and_at_them.rb', line 32 def run finished_tasks = [] begin @tasks.each do |task| task.call finished_tasks << task end rescue => err finished_tasks.reverse_each do |task| task.rollback end raise err end end |