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

Give Enum types a name with meaningful information #460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

krainboltgreene
Copy link

The name of enum types don't display their state information.

Given: Strict::String.enum(['pending', 'active', 'frozen', 'in_review', 'banned', 'incomplete']).optional.name
Before: String | NilClass
After: String[pending|active|frozen|in_review|banned|incomplete] | NilClass

The name of enum types don't display their state information.

Given: `Strict::String.enum(['pending', 'active', 'frozen', 'in_review', 'banned', 'incomplete']).optional.name`
Before: `String | NilClass`
After: `String[pending|active|frozen|in_review|banned|incomplete] | NilClass`
@krainboltgreene
Copy link
Author

I can add tests/docs after I get some feedback (or none if this isn't desired).

@flash-gordon
Copy link
Member

This makes perfect sense to me.

@krainboltgreene
Copy link
Author

So I just used this as a patch in my own project and I'm noticing that Strict::String.enum([:a, :b, :c])['a'] raises a constraint error. First off I'm not sure why that type annotation is allowed if they're not the same? Maybe I should write a patch for that as well? And second this seems to imply we should call inspect() on the values.

@flash-gordon
Copy link
Member

flash-gordon commented Sep 6, 2023

So I just used this as a patch in my own project and I'm noticing that Strict::String.enum([:a, :b, :c])['a'] raises a constraint error. First off I'm not sure why that type annotation is allowed if they're not the same? Maybe I should write a patch for that as well?

Can you file a separate issue on this? It's not hard to fix, we just don't seem to check that passed values meet the constraints. We already fixed in for default types so that Types::String.default(:a) throws an error

And second this seems to imply we should call inspect() on the values.

I agree, but I suggest skipping .inspect on strings. The output would be nicer.

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

2 participants