Class: Aloe::TransactionRollback

Inherits:
Struct
  • Object
show all
Defined in:
lib/aloe/transaction_rollback.rb

Overview

Use case class for rolling back a transaction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#transactionObject

Returns the value of attribute transaction

Returns:

  • (Object)

    the current value of transaction



3
4
5
# File 'lib/aloe/transaction_rollback.rb', line 3

def transaction
  @transaction
end

Instance Method Details

#rollback!Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/aloe/transaction_rollback.rb', line 5

def rollback!
  ActiveRecord::Base.transaction do
    e1 = credit_entry..create_entry debit_entry.amount.cents
    e2 = debit_entry..create_entry credit_entry.amount.cents
    rollback = Aloe::Transaction.create! credit_entry: e2,
      debit_entry: e1,
      category: Aloe::ROLLBACK_TRANSACTION
    transaction.update_attribute :adjustment_transaction, rollback
  end
end