Require `opts` to be passed to `define`’d code interface
- Dominant language
- Elixir
- Stars
- 2.5k
- Forks
- 422
- Avg merge
- 23h 26m
- Merged PRs (30d)
- 46
Description
**Is your feature request related to a problem? Please describe.**
Is there any way with a code interface to require that opts are passed? I want opts to be required as we always want `tenant` and `actor` to be passed in (or in the future world, `scope` to be passed).
This would mean given `define :create_agreement, action: :create` on a domain, that `create_agreement/2` is defined but `create_agreement/1` is not. I want calling `create_agreement/1` to be a compile-time error.
**Describe the solution you'd like**
Pass in `require_opts?: true`.
**Describe alternatives you've considered**
Some sort of post-compile callback on the module to override the defined functions to error when not passing `opts`. Probably fragile.
**Express the feature either with a change to resource syntax, or with a change to the resource interface**
`require_opts?: true` added on the `resource`:
```elixir
resources do
resource MyApp.Agreement, require_opts?: true do
define :create_agreement, action: :create
define :read_agreements, action: :read
define :update_agreement, action: :update
define :destroy_agreement, action: :destroy
end
end
```
or on each `define`:
```elixir
resources do
resource MyApp.Agreement do
define :create_agreement, action: :create, require_opts?: true
define :read_agreements, action: :read, require_opts?: true
define :update_agreement, action: :update, require_opts?: true
define :destroy_agreement, action: :destroy, require_opts?: true
end
end
```
**Additional context**
This is in a multi-tenanted app so I always want the `tenant` to be passed, and also the `actor` to be required.
Contributor guide
Research direction
Start by tracing the resource interface and the `define` declarations described in the issue, including how resource-level and per-define options are handled. Compare both proposed `require_opts?` placements and verify that a required-options definition exposes only the arity-2 function and makes arity-1 calls fail at compile time.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elixir
- Domain
- backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100