haye.cr
Haye.cr
Based on the javascript version.
Haye is a simple super fast string expression parser. In support pipe and qs string expressions ( explained below ).
Pipe expression
The pipe based expression is very popular in Laravel community, due to their Validation engine, and same is adopted by Indicative.
Syntax example:
required|email|max:4|range:10,30
- Each item is separated by
| - The values are defined after
: - Multiple values are separated by
,. - White spaces in keys are trimmed.
Installation
- Add the dependency to your
shard.yml:
dependencies:
haye.cr:
github: krthr/haye.cr
- Run
shards install
Usage
require "haye.cr"
Pipe -> Array
expression = 'required|email:unique,users'
parsed = Haye.fromPipe(expression) # Haye.fromPipe(expression, Haye::PresenterTypes::Array)
Output (Haye::Presenters::Node[])
[
#<Haye::Presenters::Node:0x7f11fd891e40
@name="required",
@args=[]
>,
#<Haye::Presenters::Node:0x7f11fd891de0
@name="email",
@args=["unique", "users"]
>
]
Pipe -> Hash
expression = 'required|email:unique,users'
parsed = Haye.fromPipe(expression, Haye::PresenterTypes::Hash)
Output (Hash)
{
"required" => [],
"email" => ["unique", "users"]
}
Contributing
- Fork it (https://github.com/krthr/haye.cr/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
- krthr - creator and maintainer