sinatra-param icon indicating copy to clipboard operation
sinatra-param copied to clipboard

allows :in, :within, :range validations to be used on Array params

Open janfoeh opened this issue 9 years ago • 2 comments

This makes it possible to support situations such as

param :sort_by, Array, in: ['id ASC, 'id DESC, 'name ASC', 'name DESC']

Range checks against array elements are also supported, but currently require you to coerce the Array elements manually first:

param :arg, Array, within: 1..10, transform: ->(a) { a.map(&:to_i) }

janfoeh avatar Feb 02 '16 15:02 janfoeh

Thank you for this, @janfoeh. I apologize for the delay in getting back to you.

sinatra-param borrows a lot of its conventions from Active Model validations in Rails. I'd thought that the Rails counterpart to our inclusion check was member to collection, but it looks like it indeed supports member-wise checks for enumerable values as well. As such, this suggested feature would fix sinatra-param to be more in line with expected behavior.

I'm investigating some significant refactoring for the next major release, but would like to incorporate this functionality in the process.

mattt avatar Mar 20 '18 16:03 mattt

@mattt any chance this will get incorporated?

RaVbaker avatar Jul 02 '19 13:07 RaVbaker