luckyframework / luckyframework/lucky
Add optional_param with enums
Nobody has claimed this yet.
- Dominant language
- Crystal
- Stars
- 2.7k
- Forks
- 172
- PR merge metrics
- No merged PRs in 30d
Description
This sets up some enums so you can have type safe params
```crystal
class Tasks::Index
# `allow` will create an enum
param filter, default: All, allow: [All, Completed, Incomplete]
action do
# This will be extra cool/if when they have exhaustiveness checks on enums!
case Filter
when All
tasks = TaskQuery.all
when Completed
tasks = TaskQuery.new.completed
when Incomplete
tasks = TaskQuery.new.incomplete
end
render tasks: tasks
end
end
# You can only use things in the enum when using a route
link "complete", to: Tasks::Index.route(filter: Tasks::Index::Filter::Completed)
```
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the issue's Crystal examples for `optional_param`, the `allow` enum declaration, and route generation. Determine how enum values should be represented in params and routes, then define completion around type-safe filtering and restricting route links to the declared enum values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- crystal
- Domain
- backend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100