./README.md in sinatra-param-1.3.1 vs ./README.md in sinatra-param-1.4.0

- old
+ new

@@ -9,10 +9,24 @@ **`sinatra-param` allows you to declare, validate, and transform endpoint parameters as you would in frameworks like [ActiveModel](http://rubydoc.info/gems/activemodel/3.2.3/frames) or [DataMapper](http://datamapper.org/).** > Use `sinatra-param` in combination with [`Rack::PostBodyContentTypeParser` and `Rack::NestedParams`](https://github.com/rack/rack-contrib) to automatically parameterize JSON `POST` bodies and nested parameters. +## Install + +You can install `sinatra-param` from the command line with the following: + +```bash +$ gem install sinatra-param +``` + +Alternatively, you can specify `sinatra-param` as a dependency in your `Gemfile` and run `$ bundle install`: + +```ruby +gem "sinatra-param", require: "sinatra/param" +``` + ## Example ``` ruby require 'sinatra/base' require 'sinatra/param' @@ -79,22 +93,33 @@ ```ruby param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC" param :offset, Integer, min: 0, transform: lambda {|n| n - (n % 10)} ``` -### Mutual Exclusivity +## One Of -Using `one_of`, routes can specify two or more parameters to be mutually exclusive, and fail if more than one of those parameters is specified: +Using `one_of`, routes can specify two or more parameters to be mutually exclusive, and fail if _more than one_ of those parameters is provided: ```ruby param :a, String param :b, String param :c, String one_of :a, :b, :c ``` +## Any Of + +Using `any_of`, a route can specify that _at least one of_ two or more parameters are required, and fail if _none of them_ are provided: + +```ruby +param :x, String +param :y, String + +any_of :x, :y +``` + ### Exceptions By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400` with an error message: ```json @@ -124,14 +149,10 @@ one_of :q, :categories, raise: true ``` ## Contact -Mattt Thompson +Mattt Thompson ([@mattt](http://twitter.com/mattt)) -- http://github.com/mattt -- http://twitter.com/mattt -- m@mattt.me - ## License -sinatra-param is available under the MIT license. See the LICENSE file for more info. +sinatra-param is released under an MIT license. See LICENSE for more information.