Rack::Param
Parameter checking and validation for Rack::Request. Originally designed to be used with Sansom, but it also works with Rack.
Installation
Add this line to your application's Gemfile:
gem 'rack-param'
And then execute:
$ bundle
Or install it through gem:
$ gem install rack-param
Usage
require "rack/param"
r = Rack::Request env # pass your env
r.param :param_name, Integer, :required => true ...
Now, r.params should contain a single entry:
{ :param_name => <some Integer> }
Rack::Param patches Rack::Request#params to contain only the validated parameters, in coerced form.
Here's a list of options:
:required => true/false
:blank => true/false
:greater_than => Any Numeric
:less_than => Any Numeric
:min => Any Numeric
:max => Any Numeric
:length => Any Numeric
:min_length => Any Numeric
:max_length => Any Numeric
:in => Something that responds to include?
:regex => A Regexp
:validator => A block: { |param| true }
:error_message => A String. $ is the parameter and # is the validator object. ("Invalid password: $")
Contributing
- Fork it ( https://github.com/sansomrb/rack-param/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