mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-01 10:37:12 +08:00
This patch introduces a new step to the Ruby Service Framework. `only_if` will execute its block (other steps) only if the provided condition evaluates to `true`. As for the other steps, the name provided is the name of the method that will be executed. ```ruby only_if(:can_update) do model :user step :update_user step :notify end private def can_update(guardian:) … end ``` This step cannot fail and the whole block will be skipped if the method evaluates to a falsy value. This is rendered by the steps inspector: ``` [ 1/13] [options] default ✅ [ 2/13] [model] model ✅ [ 3/13] [policy] policy ✅ [ 4/13] [params] default ✅ [ 5/13] [lock] parameter:other_param ✅ [ 6/13] [transaction] [ 7/13] [step] in_transaction_step_1 ✅ [ 8/13] [step] in_transaction_step_2 ✅ [ 9/13] [try] [10/13] [step] might_raise ✅ [11/13] [only_if] condition ⏭️ (condition was not met) [12/13] [step] optional_step [13/13] [step] final_step ✅ ``` The inspector also renders text with colors now. <img width="419" height="336" alt="Copie d'écran_20251008_162920" src="https://github.com/user-attachments/assets/add4fd16-076e-4f30-ae1a-3e933494967e" /> |
||
|---|---|---|
| .. | ||
| db/migrate | ||
| fabricators | ||
| fixtures | ||
| generator | ||
| helpers | ||
| import_export | ||
| initializers | ||
| integration | ||
| integrity | ||
| jobs | ||
| lib | ||
| mailers | ||
| models | ||
| multisite | ||
| queries/reports | ||
| requests | ||
| script/import_scripts | ||
| serializers | ||
| services | ||
| support | ||
| system | ||
| tasks | ||
| views | ||
| rails_helper.rb | ||
| regenerate_swagger_docs | ||
| swagger_helper.rb | ||