Module: ActiveRecord::Transactions
Relationships & Source Files | |
Namespace Children | |
Modules:
| |
Extension / Inclusion / Inheritance Descendants | |
Included In:
| |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::ActiveSupport::Concern
|
|
Defined in: | activerecord/lib/active_record/transactions.rb |
Overview
See ClassMethods
for documentation.
Class Method Summary
::ActiveSupport::Concern
- Extended
class_methods | Define class methods from given block. |
included | Evaluate given block in context of base class, so that you can write class macros here. |
prepended | Evaluate given block in context of base class, so that you can write class macros here. |
Instance Method Summary
-
#transaction(**options, &block)
See
ClassMethods
for detailed documentation. -
#with_transaction_returning_status
Executes a block within a transaction and captures its return value as a status flag.
DSL Calls
included
[ GitHub ]10 11 12 13 14
# File 'activerecord/lib/active_record/transactions.rb', line 10
included do define_callbacks :commit, :rollback, :before_commit, scope: [:kind, :name] end
Instance Method Details
#transaction(**options, &block)
See Transactions::ClassMethods
for detailed documentation.
# File 'activerecord/lib/active_record/transactions.rb', line 300
def transaction(**, &block) self.class.transaction(**, &block) end
#with_transaction_returning_status
Executes a block within a transaction and captures its return value as a status flag. If the status is true, the transaction is committed, otherwise a ROLLBACK is issued. In any case, the status flag is returned.
This method is available within the context of an Base
instance.
# File 'activerecord/lib/active_record/transactions.rb', line 356
def with_transaction_returning_status status = nil connection = self.class.connection ensure_finalize = !connection.transaction_open? connection.transaction do add_to_transaction(ensure_finalize || has_transactional_callbacks?) remember_transaction_record_state status = yield raise ActiveRecord::Rollback unless status end status end