module ActiveRecord::Locking::Pessimistic

def with_lock(*args)

ActiveRecord::ConnectionAdapters::DatabaseStatements#transaction).
and joinable: to the wrapping transaction (see
You can also pass options like requires_new:, isolation:,

as an optional argument (see #lock!).
before yielding. You can pass the SQL locking clause
Wraps the passed block in a transaction, locking the object
def with_lock(*args)
  transaction_opts = args.extract_options!
  lock = args.present? ? args.first : true
  transaction(**transaction_opts) do
    lock!(lock)
    yield
  end
end