Class: PikoTransaction::Transaction

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/piko_transaction/transaction.rb

Instance Method Summary collapse

Methods included from Logger

#logger

Constructor Details

#initialize(name = nil) {|_self| ... } ⇒ Transaction

Returns a new instance of Transaction.

Yields:

  • (_self)

Yield Parameters:



26
27
28
29
30
31
# File 'lib/piko_transaction/transaction.rb', line 26

def initialize(name = nil)
  @name = name
  @commands = []
  @done = []
  yield self if block_given?
end

Instance Method Details

#add(command) ⇒ Object



33
34
35
36
37
38
# File 'lib/piko_transaction/transaction.rb', line 33

def add(command)
  @commands << command
  logger.debug do
    format "%s Added command: %s, total: %i", to_s, command.to_s, @commands.count
  end
end

#doObject



40
41
42
43
44
# File 'lib/piko_transaction/transaction.rb', line 40

def do
  logger.info { format "%s Start transaction with commands: %s", to_s, @commands.count }
  return true if run_commands
  terminate_and_undo
end

#to_sObject



51
52
53
# File 'lib/piko_transaction/transaction.rb', line 51

def to_s
  format "[%s]", @name || "tr"
end

#undoObject



46
47
48
49
# File 'lib/piko_transaction/transaction.rb', line 46

def undo
  logger.info { format "%s Rolling back transaction with commands: %s", to_s, @done.count }
  undo_done_commands
end