therapy
Therapy
Get it? Therapy... validation... come on!
Installation
-
Add the dependency to your
shard.yml
:dependencies: therapy: github: matthewmcgarvey/therapy
-
Run
shards install
Usage
require "therapy"
sign_up_form = Therapy.object(
email: Therapy.string.coercing,
password: Therapy.string.coercing,
confirm: Therapy.string.coercing
).coercing.validate("Confirm must match password") do |form|
form[:password] == form[:confirm]
end
json = JSON.parse(request.body)
sign_up = sign_up_form.parse!(json) #=> NamedTuple(email: String, password: String, confirm: String)
TODO: Write usage instructions here
Development
TODO: Write development instructions here
TODO
- Support enums
- Cascade coercion so that you don't have to specify it on every attribute
- This could be a bad idea
- I want to be able to coerce json, not necessarily coerce ints to string
- What I really want is for json parsing to turn fields into the string value when the parent is coercing
- this is probably why I originally had object pulling the raw value from JSON::Any when passing to coerce instead of passing the json
- Allow specifying the path on the object validation
- When checking password confirmation, the path of the error should point towards it
Contributing
- Fork it (https://github.com/matthewmcgarvey/therapy/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- matthewmcgarvey - creator and maintainer
Repository
therapy
Owner
Statistic
- 0
- 0
- 0
- 0
- 0
- almost 2 years ago
- November 26, 2022
License
MIT License
Links
Synced at
Sun, 24 Nov 2024 08:40:50 GMT
Languages