Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

janfoeh
Copy link

@janfoeh janfoeh commented Feb 2, 2016

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) }

@mattt
Copy link
Owner

mattt commented Mar 20, 2018

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.

@RaVbaker
Copy link

RaVbaker commented Jul 2, 2019

@mattt any chance this will get incorporated?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants