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

Range enum #22

Closed
wants to merge 8 commits into from
Closed

Range enum #22

wants to merge 8 commits into from

Conversation

marcandre
Copy link
Contributor

This PR improves handling of param :foo, enum: 1..1000. It also allows float enums.

This builds on #21; only the last commit is new.

Note: it's not clear to me why the API allows type: {a: 1}, enum: {a: 1} and enum: 1..42 but not type: 1..42. I find this inconsistent and would suggest to either allow it, or forbid type: {...}. This PR doesn't address this.

Copy link
Contributor

@zverok zverok left a comment

Choose a reason for hiding this comment

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

Looks good to me, just have one point to clarify.

About type: {} -- yes, it was probably a false move from my side.
The sad story of this library is: the project I needed it for, is indefinitely postponed, and the library hangs in an "it is the prototype, we'll clarify a lot of things later" since then (some parts of what I've written 2 years ago surprised me myself, TBH)
I still not sure if I just want to "let the library go" (e.g. probably move it to another maintainer), as I kinda have a clear vision for a lot of things in the future, and haven't given up completely on the ideas...

That's where the weird state of things come from. I'll try to do something on it (either reschedule my activity to become a more reasonable maintainer or else).

end

def validation_error(value)
return 'is not an Integer' if type.begin.is_a?(Integer) && !value.is_a?(Integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

This seem surprisingly narrow. Care to explain?..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the range is 1..42, then only integer values would be acceptable. If the range is 1.0..42.0, then float or integers would be ok. I don't need the floating range personally, but I thought supporting it this way made sense.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm ok, let's leave it this way for now. My intuition says it means we need to somehow separate "expected type" and "expected range" from range, but it is non-trivial (because naive solution would prohibit integer for float ranges, for example), so may be I am overthinking. So let's clarify this thing with validate_error in neighbour PR, and then merge.

@marcandre
Copy link
Contributor Author

I don't plan on rebasing this PR in the near future.

@zverok
Copy link
Contributor

zverok commented Dec 21, 2018

I understand.
I'll take a look into a possible API for ranges myself. After the refactoring is complete, I need to think about further directions for the library. Really want to keep things tidy, it is already overthought at some points (for ex., response processing, as discussed here) and I feel like param(...) DSL API starts to get out of hand, becoming one more of thousands of "typed attr DSL for Ruby" already in presence.

@marcandre marcandre closed this Jun 26, 2020
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