luckyframework / lucky

A full-featured Crystal web framework that catches bugs for you, runs incredibly fast, and helps you write code that lasts.
https://luckyframework.org
MIT License
2.59k stars 156 forks source link

Replace avram parsing with ParamParser #1616

Closed matthewmcgarvey closed 2 years ago

matthewmcgarvey commented 2 years ago

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?

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