Class: Promiscuous::Publisher::Context::Transaction

Inherits:
Object
  • Object
show all
Defined in:
lib/promiscuous/publisher/context/transaction.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#driverObject

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

#commitObject



29
30
31
# File 'lib/promiscuous/publisher/context/transaction.rb', line 29

def commit
  @indexes.pop
end

#in_transaction?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/promiscuous/publisher/context/transaction.rb', line 33

def in_transaction?
  !@indexes.empty?
end

#rollbackObject



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

#startObject



11
12
13
# File 'lib/promiscuous/publisher/context/transaction.rb', line 11

def start
  @indexes << @write_operations.size
end

#write_operations_to_commitObject



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