https://github.com/sirscriptalot/preform
Validation for Rack params.
https://github.com/sirscriptalot/preform
params rack validation
Last synced: 12 months ago
JSON representation
Validation for Rack params.
- Host: GitHub
- URL: https://github.com/sirscriptalot/preform
- Owner: sirscriptalot
- License: mit
- Created: 2017-08-11T18:03:43.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-11T20:07:06.000Z (over 8 years ago)
- Last Synced: 2024-04-25T17:20:39.927Z (almost 2 years ago)
- Topics: params, rack, validation
- Language: Ruby
- Homepage:
- Size: 3.91 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Preform
A small library for validating user input. It includes a mixin,
Validatable, and two opinionated classes that include it: Form, and Field.
## Usage
### Installation
`gem install preform`
### API
#### Validatable
`validate`: Template command method that needs to be implemented. Runs to determine errors.
`valid?`: Query to see if any errors exist.
`errors`: Returns the errors hash.
`merge_errors!`: Given another validatable, merges errors into self's errors.
`assert`: Tests a value to see if an error should be added or not. Always returns a boolean so asserts can be nested.
#### Form
`after_initialize`: Override to perform custom initialization behavior.
`params`: Raw params given to the form.
`attributes`: Hook that allows you to transform params for use in your application. By default returns raw params.
#### Field
`after_initialize`: Override to perform custom initialization behavior.
`key`: Reader for the form key, used when merging errors into a form.
`value`: Raw value to validate.