./README.md in sinatra-param-1.1.0 vs ./README.md in sinatra-param-1.1.1

- old
+ new

@@ -60,27 +60,37 @@ - `in`, `within`, `range` - `min` / `max` ### Defaults and Transformations -Passing a `default` option will provide a default value for a parameter if none is passed. +Passing a `default` option will provide a default value for a parameter if none is passed. A `default` can defined as either a default or as a `Proc`: -Use the `transform` option to take even more of the business logic of parameter I/O out of your code. Anything that responds to `to_proc` (including Procs and symbols) will do. +```ruby +param :attribution, String, default: "©" +param :year, Integer, default: lambda { Time.now.year } +``` +Use the `transform` option to take even more of the business logic of parameter I/O out of your code. Anything that responds to `to_proc` (including `Proc` and symbols) will do. + +```ruby +param :order, String, in: ["ASC", "DESC"], transform: :upcase, default: "ASC" +param :offset, Integer, min: 0, transform: lambda {|n| n - (n % 10)} +``` + ### Exceptions By default, when a parameter precondition fails, `Sinatra::Param` will `halt 400` with an error message: ```json { + "message": "Invalid parameter, order", "errors": { "order": "Param must be within [\"ASC\", \"DESC\"]" - }, - "message": "Invalid parameter, order" + } } ``` -To change this, you can set `:raise_sinatra_param_exceptions` to `true`, and intercept `Sinatra::Param::InvalidParameterError` with a Sinatra `error do...end` block. _(To make this work in development, set `:show_exceptions` to `false`)_: +To change this, you can set `:raise_sinatra_param_exceptions` to `true`, and intercept `Sinatra::Param::InvalidParameterError` with a Sinatra `error do...end` block. (To make this work in development, set `:show_exceptions` to `false`): ```ruby set :raise_sinatra_param_exceptions, true error Sinatra::Param::InvalidParameterError do