Attribute API 2

**NOTE:** This RFC is incomplete, the specification of the new feature is TBD.

This RFC describes a new attributes API to be added alongside the current one. The goals of this new API are:

* Separate desired and observed state.
* Structure the syntax in a way that "trainwreck" errors
  (`NoMethodError` for `[]` on `nil`) can be avoided.
* Structure the syntax in a way that attribute tracing can be
  implemented simply.
* Separate node-specific persistent storage from
  cookbook/role/environment attributes.
* Structure the syntax in a way that can be implemented efficiently.

This RFC is adapted from https://github.com/opscode/chef-rfc/pull/9 which is retracted.
For the record, I'm -1 on the new syntax using square brackets at all. We
need to make it clear it isn't a hash.
On Dec 16, 2014 6:45 PM, "Dan DeLeo" <notifications@github.com> wrote:

> In new/rfcXXX-new-attributes-api-syntax.rb
> <https://github.com/opscode/chef-rfc/pull/77#discussion-diff-21949584>:
>
> > +
> > +## Array path option
> > +default_attr(["mysql", "version"], "1.2.3")
> > +
> > +## Multi-arg element assignment operator option:
> > +
> > +default_attr["mysql", "version"] = "1.2.3"
> > +
> > +## Method chaining:
> > +
> > +default_attr("mysql", "version").to("1.2.3")
> > +
> > +# Mass Default assignment
> > +
> > +## Block w/ block variable, method chaining
> > +defaults_for("mysql") do |mysql|
>
> You can splat in element reference and assignment, so this will work:
>
> thing['foo', 'bar', 'baz'] = 1
>
> I don't know if that's terrible or not; but it's also ambiguous what n["foo.bar.baz"]
> = 1 means if we implemented the dots shortcut. I would be [image: :-1:]
> on the obeying the dot shortcut rule if we adopted syntax like that,
> personally, though.
>
> Anyway, you can't do the assignment-y thing with parens, only square
> brackets.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/opscode/chef-rfc/pull/77/files#r21949584>.
>