Module: InteractorSupport::Concerns::Transactionable

Extended by:
ActiveSupport::Concern
Includes:
InteractorSupport::Core
Defined in:
lib/interactor_support/concerns/transactionable.rb

Overview

Adds transactional support to your interactor using ActiveRecord.

The transaction method wraps the interactor execution in an around block that uses ActiveRecord::Base.transaction. If the context fails (via context.fail!), the transaction is rolled back automatically using ActiveRecord::Rollback.

This is useful for ensuring your interactor behaves atomically.

Examples:

Basic usage

class CreateUser
  include Interactor
  include InteractorSupport::Transactionable

  transaction

  def call
    User.create!(context.user_params)
    context.fail!(message: "Simulated failure") if something_wrong?
  end
end

See Also:

Method Summary

Methods included from InteractorSupport::Core

included