Clear provides a way to create triggers on different time of the lifecycle of the model.
class Userinclude Clear::Modelcolumn first_name : Stringcolumn last_name : Stringdef full_name{first_name, last_name}.join(" ")endafter :create, :send_emailbefore(:update) { |m| m.as(User).updated_at = Time.local }def send_emailEmailManager.send_email(subject: "welcome #{full_name} !", body: "...")endend
Calling before/after with a block will return a Clear::Model as argument. Therefore, you must cast the variable (m.as(User)
in example above).
before/after :action, :method
must be pointing to public method. If the method is private, the call will fail.
Trigger symbol | Description |
| Is triggered before and after calling |
| Is triggered before and after calling |
| Is triggered before and after destroying a model |
| Is triggered before and after calling |
| Is triggered before and after calling |
| Note: PLANNED FEATURE NOT YET IMPLEMENTED. Is triggered when a transaction is commited, for each model which has been created during the lifetime of a transaction |
| Note: PLANNED FEATURE NOT YET IMPLEMENTED. Is triggered when a transaction is commited, for each model which has been updated during the lifetime of a transaction |
| Note: PLANNED FEATURE NOT YET IMPLEMENTED. Is triggered when a transaction is commited, for each model which has been destroyed during the lifetime of a transaction |