Class: Promiscuous::Publisher::Context::Transaction
- Inherits:
-
Object
- Object
- Promiscuous::Publisher::Context::Transaction
- Defined in:
- lib/promiscuous/publisher/context/transaction.rb
Instance Attribute Summary collapse
-
#driver ⇒ Object
Returns the value of attribute driver.
Instance Method Summary collapse
- #add_write_operation(operation) ⇒ Object
- #commit ⇒ Object
- #in_transaction? ⇒ Boolean
-
#initialize(driver) ⇒ Transaction
constructor
A new instance of Transaction.
- #rollback ⇒ Object
- #start ⇒ Object
- #write_operations_to_commit ⇒ Object
Constructor Details
#initialize(driver) ⇒ Transaction
Returns a new instance of Transaction.
4 5 6 7 8 9 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 4 def initialize(driver) @driver = driver @indexes = [] @write_operations = [] end |
Instance Attribute Details
#driver ⇒ Object
Returns the value of attribute driver.
2 3 4 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 2 def driver @driver end |
Instance Method Details
#add_write_operation(operation) ⇒ Object
15 16 17 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 15 def add_write_operation(operation) @write_operations << operation end |
#commit ⇒ Object
29 30 31 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 29 def commit @indexes.pop end |
#in_transaction? ⇒ Boolean
33 34 35 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 33 def in_transaction? !@indexes.empty? end |
#rollback ⇒ Object
24 25 26 27 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 24 def rollback transaction_index = @indexes.pop @write_operations.slice!(transaction_index..-1) end |
#start ⇒ Object
11 12 13 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 11 def start @indexes << @write_operations.size end |
#write_operations_to_commit ⇒ Object
19 20 21 22 |
# File 'lib/promiscuous/publisher/context/transaction.rb', line 19 def write_operations_to_commit transaction_index = @indexes.last @write_operations[transaction_index..-1] end |