dry-types icon indicating copy to clipboard operation
dry-types copied to clipboard

Give Enum types a name with meaningful information

Open krainboltgreene opened this issue 1 year ago • 4 comments

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 avatar Aug 31 '23 21:08 krainboltgreene

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

krainboltgreene avatar Aug 31 '23 21:08 krainboltgreene

This makes perfect sense to me.

flash-gordon avatar Sep 01 '23 06:09 flash-gordon

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.

krainboltgreene avatar Sep 01 '23 16:09 krainboltgreene

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.

flash-gordon avatar Sep 06 '23 11:09 flash-gordon