-
Notifications
You must be signed in to change notification settings - Fork 39
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 symbols as flag names #221
base: main
Are you sure you want to change the base?
Conversation
Hi @Bertg thanks for the contribution, not a Ruby expert, so I'll checkout the code and test myself a bit, but sounds like a good contribution |
Pull Request Test Coverage Report for Build 12414881422Details
💛 - Coveralls |
@gastonfournier one possible change would be to move this to |
I think it's better how you did it, it's better to convert feature names to string in the edge of the API layer, so internally we only worry about feature as strings. That's also what the other SDKs do, the strongly typed ones only accept strings but in the case of Ruby, calling to_s on the feature seems correct. |
An alternative would be to validate that the feature is a string and thrown an error, but that would result in a runtime error with the only difference that the error could be more meaningful. The point being that Unleash API only accepts strings, but this feels like a gray area for languages like ruby where you can't force a type constraint at compile time... |
After talking with the team, we're more inclined to keep the API interface as requiring a string. If there's a need of using symbols, the conversion should be done in the surrounding code as other SDKs do. The representation of flags in the application domain, can also be done with objects and to_s doesn't solve that problem. E.g. you could have: class MyDomainFeature
attr_accessor :name, :default_behavior and in such case you should extract the name from We can keep this open to collect additional feedback, especially since we are in holiday season and some of the main contributors are out these days. |
We've talked about it with @sighphyre and we want to also get insights from @rarruda before making a final decision. Just keeping you posted. |
Hey @Bertg, so I actually quite like this. I think it's consistent with the way we do context fields and generally with most Ruby development. I have two small concerns:
Other than that I think this is worth doing |
OK, I can adjust the PR. But what should we do if we receive something that's is neither a string or symbol? I have a few suggestions:
I would opt for But your call, and I'll adjust the PR |
I'm tempted to say "let it happen, write something to the error log rather than warn". It's a pretty serious issue in that your flags are definitely not evaluating the way you think they should be but the philisophy of all our SDKs is to default to false rather than fail when and where they can (I'm pretty sure passing goop will result in a false here) |
About the changes
This PR allows developers to specify flag names as symbols. Ruby developers will often use symbols instead of flag names.
Discussion points
If this PR is not accepted it would be useful to have some sort of clear error at runtime. Today the lib will raise
TypeError: no implicit conversion of Symbol into String
this is not super useful to the developer.