Class: PikoTransaction::Transaction
- Inherits:
-
Object
- Object
- PikoTransaction::Transaction
- Includes:
- Logger
- Defined in:
- lib/piko_transaction/transaction.rb
Instance Method Summary collapse
- #add(command) ⇒ Object
- #do ⇒ Object
-
#initialize(name = nil) {|_self| ... } ⇒ Transaction
constructor
A new instance of Transaction.
- #to_s ⇒ Object
- #undo ⇒ Object
Methods included from Logger
Constructor Details
#initialize(name = nil) {|_self| ... } ⇒ Transaction
Returns a new instance of Transaction.
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 |
#do ⇒ Object
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_s ⇒ Object
51 52 53 |
# File 'lib/piko_transaction/transaction.rb', line 51 def to_s format "[%s]", @name || "tr" end |
#undo ⇒ Object
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 |