Class: Yapper::DB::Transaction
- Inherits:
-
Object
- Object
- Yapper::DB::Transaction
- Defined in:
- lib/yapper/db.rb
Instance Attribute Summary collapse
-
#txn ⇒ Object
Returns the value of attribute txn.
Instance Method Summary collapse
-
#initialize(db) ⇒ Transaction
constructor
A new instance of Transaction.
- #run(&block) ⇒ Object
Constructor Details
#initialize(db) ⇒ Transaction
Returns a new instance of Transaction.
173 174 175 |
# File 'lib/yapper/db.rb', line 173 def initialize(db) @db = db end |
Instance Attribute Details
#txn ⇒ Object
Returns the value of attribute txn.
171 172 173 |
# File 'lib/yapper/db.rb', line 171 def txn @txn end |
Instance Method Details
#run(&block) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/yapper/db.rb', line 177 def run(&block) result = nil txn_proc = proc do |_txn| @txn = _txn begin result = block.call(@txn) rescue Exception => e @txn.rollback result = e end end @db.connection.readWriteWithBlock(txn_proc) raise result if result.is_a?(Exception) result end |