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

Allow parameters with more than one type. #1188

Merged
merged 1 commit into from
Oct 21, 2015

Conversation

dslh
Copy link
Contributor

@dslh dslh commented Oct 19, 2015

Fixes #693.

Adds types option for requires and optional endpoint parameter
declarations, allowing for parameters that have more than one allowed
type. See README.md for usage.

I have been thinking about the best way to expose some of the more
interesting possibilities for arbitrary type validation that are hidden in Grape,
but in the end this is the only use case I have seen that makes sense to me.

@@ -178,12 +178,23 @@ def validates(attrs, validations)
doc_attrs = { required: validations.keys.include?(:presence) }

# special case (type = coerce)
validations[:coerce] = validations.delete(:type) if validations.key?(:type)
validations[:coerce] = validations[:type] if validations.key?(:type)
validations[:coerce] = validations.delete(:types) if validations.key?(:types)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe do something here when you have both? Should probably be an exception.

@dblock
Copy link
Member

dblock commented Oct 21, 2015

I think this is really good. I am down to merging this unless you think I should hold? Anyone else wants to comment?

Adds `types` option for `requires` and `optional` endpoint parameter
declarations, allowing for parameters that have more than one allowed
type. See README.md for usage.
@dslh
Copy link
Contributor Author

dslh commented Oct 21, 2015

There's the suggested guard and a quick stab at refactoring params_scope.rb a bit. Bundling some of this coercion stuff out could be a good move but I won't get any more time to work on this until at least the weekend. I can either do a supplemental PR or keep working on this one when I get the chance.

@dblock
Copy link
Member

dblock commented Oct 21, 2015

I will merge this and we can iterate on top.

dblock added a commit that referenced this pull request Oct 21, 2015
Allow parameters with more than one type.
@dblock dblock merged commit d721c5d into ruby-grape:master Oct 21, 2015
@dslh dslh deleted the multiple_allowed_types branch October 21, 2015 14:16
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.

2 participants