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.
230 231 232 |
# File 'lib/yapper/db.rb', line 230 def initialize(db) @db = db end |
Instance Attribute Details
#txn ⇒ Object
Returns the value of attribute txn.
228 229 230 |
# File 'lib/yapper/db.rb', line 228 def txn @txn end |
Instance Method Details
#run(&block) ⇒ Object
234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/yapper/db.rb', line 234 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 |