discourse/lib/service
Loïc Guitaut 3ed866a6c9
DEV: Add each step to service framework for collection iteration (#38759)
Services that process collections (bulk delete, bulk create, etc.)
currently require manual iteration inside a `step`, losing the
framework's built-in error handling and inspection. This adds a
first-class `each` step that brings the full service DSL inside the
iteration loop.

```ruby
  each :users do
    policy :can_delete
    step :destroy
  end
```

Each iteration receives the singularized item name (`user:`) and
`index:` as keyword arguments. If any nested step fails, iteration stops
and the failing item/index remain in context for error reporting.
Existing matchers (`fail_a_policy`, `fail_a_step`, etc.) work inside
each blocks.

A `persist:` option allows values to accumulate across iterations and
survive the loop's variable isolation:

```ruby
  each :tag_names, persist: { results: -> { { created: [], failed: [] } } } do
    step :create_tag
  end
  # context[:results] available after the loop
```

The steps inspector displays iteration progress ((3/3) on success, (1/3)
when failing at the first item, (empty collection) with ⏭️ when
skipped).
2026-04-03 09:44:03 +02:00
..
base DEV: Add each step to service framework for collection iteration (#38759) 2026-04-03 09:44:03 +02:00
action_base.rb DEV: Extract step classes from Service::Base into individual files (#37956) 2026-02-23 09:49:37 +01:00
base.rb DEV: Add each step to service framework for collection iteration (#38759) 2026-04-03 09:44:03 +02:00
contract_base.rb DEV: Replace Ruby numbered parameters by it where applicable (#37810) 2026-02-13 13:59:07 +01:00
nested_contract_type.rb DEV: Handle nested attributes in contracts (#36348) 2025-12-12 11:41:48 +01:00
options_base.rb DEV: Provide user input to services using params key 2024-10-25 09:57:59 +02:00
policy_base.rb DEV: Extract step classes from Service::Base into individual files (#37956) 2026-02-23 09:49:37 +01:00
runner.rb DEV: Replace Ruby numbered parameters by it where applicable (#37810) 2026-02-13 13:59:07 +01:00
steps_inspector.rb DEV: Add each step to service framework for collection iteration (#38759) 2026-04-03 09:44:03 +02:00