Skip to content

Outbox Model Configuration

Guillermo Aguirre edited this page Jun 15, 2023 · 1 revision

This aims to explain how we can define custom Outbox classes to be used automatically by models when the concern is included

Outboxable Concern

OUTBOX_MODEL class var

On inclusion we check if the model class has the var OUTBOX_MODEL defined. This variable specifies which Outbox class name is going to be used when making any changes to a record of that model. If it's not defined then we check on the namespace to see if there is any outbox.rb present. If there is, we use that one, if not we currently provide a default TransactionalOutbox::Outbox class to be used.

Saving changes

On save of any sort we define after hooks which take advantage of the transaction block of the hook, and call the create_outbox! method. This method is the one that uses the OUTBOX_MODEL variable to determine which class is going to be saved in the database. We can specify an event name via the arg for the method. By default it will use the action that triggered the save, e.g. create, update, destroy, conjugate them in the past tense and uppercase them, meaning it will store CREATED, UPDATED, DESTROYED.

Clone this wiki locally