Class: ActionCommand::ExecutableTransaction
- Inherits:
-
Executable
- Object
- Executable
- ActionCommand::ExecutableTransaction
- Defined in:
- lib/action_command/executable_transaction.rb
Overview
Root class for action commands that can be executed by this library. Override execute_internal to implement one, call one of the variants of ActionCommand.execute_… to execute one.
Instance Attribute Summary
Attributes inherited from Executable
Instance Method Summary collapse
-
#execute(result) ⇒ Object
starts a transaction only if we are not already within one.
Methods inherited from Executable
#api_context?, #child_context?, #execute_internal, #initialize, #rails_context?, #rake_context?, #root_context, #test_context?, #testing
Constructor Details
This class inherits a constructor from ActionCommand::Executable
Instance Method Details
#execute(result) ⇒ Object
starts a transaction only if we are not already within one.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/action_command/executable_transaction.rb', line 8 def execute(result) if ActiveRecord::Base.connection.open_transactions >= 1 super(result) else result.info('start_transaction') ActiveRecord::Base.transaction do super(result) if result.ok? result.info('end_transaction') else result.info('rollback_transaction') raise ActiveRecord::Rollback, 'rollback transaction' end end end end |