diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2016-06-27 15:38:28 -0700 |
---|---|---|
committer | Lamont Granquist <lamont@scriptkiddie.org> | 2016-06-27 15:42:06 -0700 |
commit | 86fa507226b484a71a45ef6129840bc3928be6b7 (patch) | |
tree | b6f9efaedd634dbc61418ceb78817b91af1889df /lib/chef/decorator | |
parent | 945f23be7a43d90ae7ed402d05363b3ff0c11bff (diff) | |
download | chef-86fa507226b484a71a45ef6129840bc3928be6b7.tar.gz |
Attributes v1.1 changeslcg/attributes-v1.1
- fixes *_unless behavior and set_unless_value_present hack from Chef 12
- simplifies rm_* code
- introduces functional read/write/unlink/exist? API
- deprecates method_missing access to attributes for Chef 13
- deprecates set/set_unless aliases for Chef 14
- removes MultiMash mess that I wrote for Chef 13
https://github.com/chef/chef/pull/5029 for more details
Diffstat (limited to 'lib/chef/decorator')
-rw-r--r-- | lib/chef/decorator/unchain.rb | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib/chef/decorator/unchain.rb b/lib/chef/decorator/unchain.rb new file mode 100644 index 0000000000..30179d4e63 --- /dev/null +++ b/lib/chef/decorator/unchain.rb @@ -0,0 +1,43 @@ +class Chef + class Decorator < SimpleDelegator + # + # This decorator unchains method call chains and turns them into method calls + # with variable args. So this: + # + # node.set_unless["foo"]["bar"] = "baz" + # + # Can become: + # + # node.set_unless("foo", "bar", "baz") + # + # While this is a decorator it is not a Decorator and does not inherit because + # it deliberately does not need or want the method_missing magic. It is not legal + # to call anything on the intermediate values and only supports method chaining with + # #[] until the chain comes to an end with #[]=, so does not behave like a hash or + # array... e.g. + # + # node.default['foo'].keys is legal + # node.set_unless['foo'].keys is not legal now or ever + # + class Unchain + attr_accessor :__path__ + attr_accessor :__method__ + + def initialize(obj, method) + @__path__ = [] + @__method__ = method + @delegate_sd_obj = obj + end + + def [](key) + __path__.push(key) + self + end + + def []=(key, value) + __path__.push(key) + @delegate_sd_obj.public_send(__method__, *__path__, value) + end + end + end +end |