-
Notifications
You must be signed in to change notification settings - Fork 71
-
Notifications
You must be signed in to change notification settings - Fork 71
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
Non-existent options should return nil rather than Configatron::Store #3
Comments
That sounds good in theory, would have to play around with it to see if it would work in practice. In the meantime have you tried the retrieve method? configatron.i.do.exist = [:some, :array] It will set defaults if it doesnt exist. |
Thanks for the reply. I had not tried the retrieve method. I will definitely give it a try. It's good to know something like that exists, although I still think configatron.i.dont.exist || :foo would be nicer if we could get it to work :) |
I agree that the Also, on the other hand, where the configatron is used, there should be no need to provide a default as it can/should be done during configuration (not when it is used) by setting
As a result I believe we only one thing - strict retrieval mode - this would allow configuration option to be mandatory. So if it is not present - error is raised. And its implementation is very easy.
this would ensure that the required option has been provided correctly ( |
+1 This is a very odd behavior to return an unusable object when there is no configuration. |
+1 any progress on this? |
This really can't be done. This is how configatron works. To do this would mean some serious monkey patching of NilClass and that would have some very serious repercussions in almost every application. if someone out there has a great solution for this, I'm all ears. For now I'm closing this ticket because it's just not feasible. Sorry. |
How about #44 |
Agree, #44 would cover many use cases for this issue. |
👍 |
The problem with returning an instance of Configatron::Store, as you probably already know, is that you can't do var = configatron.some_option || 'default', where some_option may or may not exist.
Because even if it does exist, a Configatron::Store object will be returned, which is truthy and therefore the || 'default' never has any effect.
Worse yet, when we try to use the value, we will inevitably get NoMethodErrors, because Configatron::Store does not act like a string or a Fixnum or any of the data types we are probably expecting our value to be.
I don't THINK there is any way to make objects of a certain class so they are not truthy (that would sure be handy though, but you can't override the logical operators like ||), so the only solution I can think of is to have configatron return (for options that are not found) a special nil object that had a method_missing added that proxied the message on to the Store instance but otherwise behaved like a normal nil. Do you think that could work?
The text was updated successfully, but these errors were encountered: