TwoFistedJustice / square-pie

An easy to use class based chainable interface for accessing the Square API.
ISC License
0 stars 0 forks source link

IDEA: for ENUM properties - value validation on setter #124

Open TwoFistedJustice opened 2 years ago

TwoFistedJustice commented 2 years ago

When a property has a set of allowed string values:

We already use enum functions to curry an interface. But that doesn't stop the user from manually passing an incompatible value via the setter.

So have two setters, one private, one public. The public one uses validator.isIn(str, values) The private one skips the validation. Which should make the program faster.

This would also require we keep an array of allowed values somewhere in the class.

We could even then add a getter for that array so user's can just pull that instead of having to look up the docs online.

TwoFistedJustice commented 2 years ago

I have created an "enum" folder in the utilities folder. The enum files hold the allowable values in an array and they also have one or more functions to facilitate building curried functions to set just the allowed values.