Class: DraftApprove::Transaction Private
- Inherits:
-
Object
- Object
- DraftApprove::Transaction
- Defined in:
- lib/draft_approve/transaction.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Logic for handling ActiveRecord database transactions, and creating DraftTransaction
records.
Class Method Summary collapse
-
.current_draft_transaction! ⇒ DraftTransaction
private
Get the current
DraftTransaction
for this thread / fiber, or raise an error if there is no currentDraftTransaction
. -
.ensure_in_draft_transaction(created_by: nil, extra_data: nil) { ... } ⇒ Object
private
Ensure the block is running in a database transaction and a
DraftTransaction
- if there’s not one already, create one. -
.in_new_draft_transaction(created_by: nil, extra_data: nil) { ... } ⇒ DraftTransaction?
private
Start a new database transaction, and create a new DraftTransaction to wrap the commands in the block.
Class Method Details
.current_draft_transaction! ⇒ DraftTransaction
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Get the current DraftTransaction
for this thread / fiber, or raise an error if there is no current DraftTransaction
71 72 73 74 75 |
# File 'lib/draft_approve/transaction.rb', line 71 def self.current_draft_transaction! raise DraftApprove::Errors::NoDraftTransactionError unless current_draft_transaction.present? current_draft_transaction end |
.ensure_in_draft_transaction(created_by: nil, extra_data: nil) { ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Ensure the block is running in a database transaction and a DraftTransaction
- if there’s not one already, create one.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/draft_approve/transaction.rb', line 48 def self.ensure_in_draft_transaction(created_by: nil, extra_data: nil) draft_transaction = current_draft_transaction if draft_transaction # There's an existing draft_transaction, just yield to the block yield else # There's no transaction - start one and yield to the block inside the # new transaction (draft_transaction, yield_return) = in_new_draft_transaction_helper(created_by: created_by, extra_data: extra_data) do yield end # ensure_in_draft_transaction is used in model.draft_save! method calls # so we want to return the result of the yield (a draft object) to the caller return yield_return end end |
.in_new_draft_transaction(created_by: nil, extra_data: nil) { ... } ⇒ DraftTransaction?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Start a new database transaction, and create a new DraftTransaction to wrap the commands in the block.
24 25 26 27 28 29 30 31 32 |
# File 'lib/draft_approve/transaction.rb', line 24 def self.in_new_draft_transaction(created_by: nil, extra_data: nil) (draft_transaction, yield_return) = in_new_draft_transaction_helper(created_by: created_by, extra_data: extra_data) do yield end # in_new_draft_transaction is used in Model.draft_transaction do ... blocks # so we want to return the transaction itself to the caller return draft_transaction end |