class Chef::Decorator::Unchain

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

Attributes

__method__[RW]
__path__[RW]

Public Class Methods

new(obj, method) click to toggle source
# File lib/chef/decorator/unchain.rb, line 26
def initialize(obj, method)
  @__path__        = []
  @__method__      = method
  @delegate_sd_obj = obj
end

Public Instance Methods

[](key) click to toggle source
# File lib/chef/decorator/unchain.rb, line 32
def [](key)
  __path__.push(key)
  self
end
[]=(key, value) click to toggle source
# File lib/chef/decorator/unchain.rb, line 37
def []=(key, value)
  __path__.push(key)
  @delegate_sd_obj.public_send(__method__, *__path__, value)
end