Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hanami/validations
Validation mixin for Ruby objects
https://github.com/hanami/validations
coercion ruby validations whitelisting
Last synced: 3 months ago
JSON representation
Validation mixin for Ruby objects
- Host: GitHub
- URL: https://github.com/hanami/validations
- Owner: hanami
- License: mit
- Created: 2014-08-05T12:49:35.000Z (about 10 years ago)
- Default Branch: main
- Last Pushed: 2024-04-28T22:29:46.000Z (6 months ago)
- Last Synced: 2024-05-23T01:24:25.516Z (5 months ago)
- Topics: coercion, ruby, validations, whitelisting
- Language: Ruby
- Homepage: http://hanamirb.org
- Size: 790 KB
- Stars: 213
- Watchers: 23
- Forks: 49
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Hanami::Validations
Internal support gem for `Hanami::Action` params validation.
## Status
[![Gem Version](https://badge.fury.io/rb/hanami-validations.svg)](https://badge.fury.io/rb/hanami-validations)
[![CI](https://github.com/hanami/validations/actions/workflows/ci.yml/badge.svg)](https://github.com/hanami/validations/actions?query=workflow%3Aci+branch%3Amain)
[![Test Coverage](https://codecov.io/gh/hanami/validations/branch/main/graph/badge.svg)](https://codecov.io/gh/hanami/validations)
[![Depfu](https://badges.depfu.com/badges/af6c6be539d9d587c7541ae7a013c9ff/overview.svg)](https://depfu.com/github/hanami/validations?project=Bundler)## Contact
* Home page: http://hanamirb.org
* Community: http://hanamirb.org/community
* Guides: https://guides.hanamirb.org
* Mailing List: http://hanamirb.org/mailing-list
* API Doc: http://rubydoc.info/gems/hanami-validations
* Bugs/Issues: https://github.com/hanami/validations/issues
* Chat: http://chat.hanamirb.org## Installation
__Hanami::Validations__ supports Ruby (MRI) 3.1+
Add this line to your application's Gemfile:
```ruby
gem "hanami-validations"
```And then execute:
```shell
$ bundle
```Or install it yourself as:
```shell
$ gem install hanami-validations
```## Usage
Installing hanami-validations enables support for `params` validation in
[hanami-controller][controller]’s `Hanami::Action` classes.```ruby
class Signup < Hanami::Action
params do
required(:first_name)
required(:last_name)
required(:email)
enddef handle(req, *)
puts req.params.class # => Signup::Params
puts req.params.class.superclass # => Hanami::Action::Paramsputs req.params[:first_name] # => "Luca"
puts req.params[:admin] # => nil
end
end
```See [hanami-controller][controller] for more detail on params validation.
[controller]: http://github.com/hanami/controller
## Contributing
1. Fork it ( https://github.com/hanami/validations/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request## Copyright
Copyright © 2014–2024 Hanami Team – Released under MIT License