Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added usage to README and travis-ci build status image

  • Loading branch information...
commit 916c1ebf0e6f8bc00bab8891eddb40913c4a6af3 1 parent 529ea0f
@chdorner authored
Showing with 93 additions and 1 deletion.
  1. +93 −1 README.md
View
94 README.md
@@ -1,9 +1,101 @@
-# params_validator
+# params_validator ![Continuous Integration](https://secure.travis-ci.org/chdorner/epubinfo.png?branch=master)
A DSL for validating request parameters, raises exceptions when validation failed. Currently only supports Rails.
Current status is very much alpha, this gem is still under development and not intended to use in production applications.
+# Installation
+
+Add this to your Gemfile and run `bundle install`
+
+ gem 'params_validator'
+
+# Usage
+
+Basic usage:
+
+ class WelcomeController < ActionController::Base
+ rescue_from ParamsValidator::InvalidParamsException do |exception|
+ render :text => 'Error', :status => :bad_request
+ end
+
+ validate_params_for :index, { :count => { :with => [:type_integer] } }
+ def index
+ @articles = Article.limit(params[:count])
+ end
+ end
+
+## Validators
+
+### TypeInteger
+
+ validate_params_for :index, { :count => { :with => [:type_integer] } }
+
+**Valid:**
+
+* `count=1`
+
+**Invalid:**
+
+* `count=something`
+* `count[]=1`
+* `count[key]=value`
+
+### TypeFloat
+
+ validate_params_for :index, { :position => { :with => [:type_float] } }
+
+**Valid:**
+
+* `position=0.42`
+* `position=1`
+
+**Invalid:**
+
+* `position=something`
+* `position[]=0.42`
+* `position[key]=0.42`
+
+### TypeString
+
+ validate_params_for :index, { :name => { :with => [:type_string] } }
+
+**Valid:**
+
+* `name=Jack`
+* `name=1`
+
+**Invalid:**
+
+* `name[]=Jack`
+* `name[key]=Jack`
+
+### TypeHash
+
+ validate_params_for :index, { :options => { :with => [:type_hash] } }
+
+**Valid:**
+
+* `options[all]=true`
+
+**Invalid:**
+
+* `options=all`
+* `options[]=all`
+
+### TypeArray
+
+ validate_params_for :index, { :ids => { :with => [:type_array] } }
+
+**Valid:**
+
+* `ids[]=1`
+
+**Invalid:**
+
+* `ids=1`
+* `ids[1]=true`
+
## Contributing to params_validator
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.

0 comments on commit 916c1eb

Please sign in to comment.
Something went wrong with that request. Please try again.