-
Notifications
You must be signed in to change notification settings - Fork 34
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
default(:option) { value } doesn't respect << when value is Array #31
Comments
@danielsdeleo @jkeiser I could use a little help on this. Default options with blocks are designed to be re-evaluated until the value is set. Using Evaluating the block the first time we see it would solve the append problem, but would break re-evaluating the default value. I've thought about overriding the |
I don't think you can both recalculate the value every time and support append. Like, if the user appends 'x', and then the next time we re-evaluate, should the value have 'x' in it or not? What if the re-evaluate returns something different than last time? Also, note that this isn't limited to What you're observing is that it's surprising that you get a value back from a property, and it lets you modify that value, and the next time you get the property value, your modification didn't stick. There are three things you can do here:
If we want to keep the semantic of default values being computed, we can do #2. If we want to flip it around, we do #1. 3 might not be possible. There are a couple of "middle ways" to get around this:
Number one is the direction we may be going for Chef resources; wherever we go, it's probably worth doing the same thing in both places so we can eventually share le code (for validation and defaults and all that jazz). |
@mcquin you can look at Chef::Node::Attribute stuff and in particular the MUTATOR_METHODS and you basically wrap all of them to both proxy to the underlying object and to 'dirty' the setting so that it isn't considered a default any more. since you proxy the call to the underlying object you should be able to simply let NoMethodErrors bubble up from that call. |
It is also worth pointing out that the user can call the setter for the value during default, causing it to be cached the first time it is set. |
The text was updated successfully, but these errors were encountered: