Module: ActiveRecord::Locking::Fatalistic
- Defined in:
- lib/active_record/locking/fatalistic.rb
Instance Method Summary collapse
-
#lock(lock_statement = nil, &block) ⇒ Object
Performs a table-level lock.
-
#unlock ⇒ Object
Unlock the table.
Instance Method Details
#lock(lock_statement = nil, &block) ⇒ Object
Performs a table-level lock. If this method is invoked with a block, then a new transaction is begun, and the table is locked inside the transaction. If invoked without a block, then it simple emits the appropriate LOCK TABLE statement.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/active_record/locking/fatalistic.rb', line 11 def lock(lock_statement = nil, &block) locker = ::Fatalistic::Locker.for(self) if block_given? transaction do begin locker.lock(lock_statement) yield ensure locker.unlock end end else locker.lock(lock_statement) end end |
#unlock ⇒ Object
Unlock the table. This is only needed by MySQL. If you called lock
with a block, then this is invoked for you automatically.
29 30 31 |
# File 'lib/active_record/locking/fatalistic.rb', line 29 def unlock ::Fatalistic::Locker.for(self).unlock end |