module

Marten::DB::Model::Callbacks

Provides the ability to define model callbacks.

This module provides the ability to define callbacks that are executed before and / or after specific model record operations (ie. initialization, creation, update, save, and deletion).

Macros

after_commit(*names, **kwargs)

Allows to define callbacks that are called after a DB commit when a record is created, updated, or deleted.

By default, the callback method will be called after record creations, updates, and deletions. It is also possible to restrict the callback to certain actions by using the on argument as follows:

after_commit :do_something, on: :create # Will run only after creations
after_commit :do_something, on: :update # Will run only after updates
after_commit :do_something, on: :update # Will run only after saves (creations or updates)
after_commit :do_something, on: :delete # Will run only after deletions

The actions supported for the on argument are create, update, save, and delete. Note that it is also possible to define that an after commit callback must run for multiple actions by using an array of actions:

after_commit :do_something, on: [:update, :delete]
Source
after_create(*names)

Allows to do define callbacks that are called after creating a model record.

Source
after_create_commit(*names)

Allows to define callbacks that are called after a DB commit when a record is created.

Source
after_create_rollback(*names)

Allows to define callbacks that are called after a DB rollback when a record is created.

Source
after_delete(*names)

Allows to do define callbacks that are called after deleting a model record.

Source
after_delete_commit(*names)

Allows to define callbacks that are called after a DB commit when a record is deleted.

Source
after_delete_rollback(*names)

Allows to define callbacks that are called after a DB rollback when a record is deleted.

Source
after_initialize(*names)

Allows to do define callbacks that are called after initializing a model record.

Source
after_rollback(*names, **kwargs)

Allows to define callbacks that are called after a DB rollback when a record is created, updated, or deleted.

By default, the callback method will be called in the context of record creations, updates, and deletions. It is also possible to restrict the callback to certain actions by using the on argument as follows:

after_rollback :do_something, on: :create # Will run only after creations
after_rollback :do_something, on: :update # Will run only after updates
after_rollback :do_something, on: :update # Will run only after saves (creations or updates)
after_rollback :do_something, on: :delete # Will run only after deletions

The actions supported for the on argument are create, update, save, and delete. Note that it is also possible to define that an after rollback callback must run for multiple actions by using an array of actions:

after_rollback :do_something, on: [:update, :delete]
Source
after_save(*names)

Allows to do define callbacks that are called after saving a model record (creation or update).

Source
after_save_commit(*names)

Allows to define callbacks that are called after a DB commit when a record is created or updated.

Source
after_save_rollback(*names)

Allows to define callbacks that are called after a DB rollback when a record is created or updated.

Source
after_update(*names)

Allows to do define callbacks that are called after updating a model record.

Source
after_update_commit(*names)

Allows to define callbacks that are called after a DB commit when a record is updated.

Source
after_update_rollback(*names)

Allows to define callbacks that are called after a DB rollback when a record is updated.

Source
before_create(*names)

Allows to do define callbacks that are called before creating a model record.

Source
before_delete(*names)

Allows to do define callbacks that are called before deleting a model record.

Source
before_save(*names)

Allows to do define callbacks that are called before saving a model record (creation or update).

Source
before_update(*names)

Allows to do define callbacks that are called before updating a model record.

Source