./README.md in sinatra-param-1.2.2 vs ./README.md in sinatra-param-1.3.0

- old
+ new

@@ -33,10 +33,12 @@ param :categories, Array param :sort, String, default: "title" param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC" param :price, String, format: "[<\=>]\s*\$\d+" + one_of :q, :categories + {...}.to_json end end ``` @@ -77,10 +79,22 @@ ```ruby param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC" param :offset, Integer, min: 0, transform: lambda {|n| n - (n % 10)} ``` +### Mutual Exclusivity + +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: + +```ruby +param :a, String +param :b, String +param :c, String + +one_of :a, :b, :c +``` + ### Exceptions By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400` with an error message: ```json @@ -104,9 +118,11 @@ Custom exception handling can also be enabled on an individual parameter basis, by passing the `raise` option: ```ruby param :order, String, in: ["ASC", "DESC"], raise: true + +one_of :q, :categories, raise: true ``` ## Contact Mattt Thompson