Where we were relying on Avram's parsing, this adds a new Lucky::ParamParser that handles it a bit differently than Avram does. Instead of adding methods to the types, there's one module with methods (with the same name) for the various types. Logically, though, it works the same. This new way is a bit nicer in that everything for parsing is in one place and not spread out in multiple files.
I did not include parsing for Enums and JSON. Unfortunately it is not possible to have a method generic for all enums and I didn't think JSON was necessary though I think it would be easy enough to add.
I have a potential solution for the enum thing though. What if param could be provided a block that gets the string value and it returns the parsed value matching their variable or nil if it couldn't be parsed?
param role : User::Role do |param|
User::Role.parse?(param)
end
Just a thought if we feel like it's absolutely necessary to support that.
Checklist
[x] - An issue already exists detailing the issue/or feature request that this PR fixes
[x] - All specs are formatted with crystal tool format spec src
[x] - Inline documentation has been added and/or updated
[x] - Lucky builds on docker with ./script/setup
[x] - All builds and specs pass on docker with ./script/test
Purpose
Fixes #1383
Description
Where we were relying on Avram's parsing, this adds a new
Lucky::ParamParser
that handles it a bit differently than Avram does. Instead of adding methods to the types, there's one module with methods (with the same name) for the various types. Logically, though, it works the same. This new way is a bit nicer in that everything for parsing is in one place and not spread out in multiple files.I did not include parsing for Enums and JSON. Unfortunately it is not possible to have a method generic for all enums and I didn't think JSON was necessary though I think it would be easy enough to add.
I have a potential solution for the enum thing though. What if
param
could be provided a block that gets the string value and it returns the parsed value matching their variable or nil if it couldn't be parsed?Just a thought if we feel like it's absolutely necessary to support that.
Checklist
crystal tool format spec src
./script/setup
./script/test