Sha256: 59f47cc4bd7e88af81386082553aae0b4e1911f2815e9173b80360abe932ba5a

Contents?: true

Size: 1.2 KB

Versions: 259

Compression:

Stored size: 1.2 KB

Contents

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

Version data entries

259 entries across 259 versions & 1 rubygems

Version Path
chef-17.10.163-universal-mingw32 lib/chef/decorator/unchain.rb
chef-17.10.163 lib/chef/decorator/unchain.rb
chef-18.5.0-x64-mingw-ucrt lib/chef/decorator/unchain.rb
chef-18.5.0 lib/chef/decorator/unchain.rb
chef-18.4.12-x64-mingw-ucrt lib/chef/decorator/unchain.rb
chef-18.4.12 lib/chef/decorator/unchain.rb
chef-17.10.122-universal-mingw32 lib/chef/decorator/unchain.rb
chef-17.10.122 lib/chef/decorator/unchain.rb
chef-17.10.114-universal-mingw32 lib/chef/decorator/unchain.rb
chef-17.10.114 lib/chef/decorator/unchain.rb
chef-18.4.2-x64-mingw-ucrt lib/chef/decorator/unchain.rb
chef-18.4.2 lib/chef/decorator/unchain.rb
chef-17.10.95-universal-mingw32 lib/chef/decorator/unchain.rb
chef-17.10.95 lib/chef/decorator/unchain.rb
chef-18.3.0-x64-mingw-ucrt lib/chef/decorator/unchain.rb
chef-18.3.0 lib/chef/decorator/unchain.rb
chef-17.10.68-universal-mingw32 lib/chef/decorator/unchain.rb
chef-18.2.7-x64-mingw-ucrt lib/chef/decorator/unchain.rb
chef-18.2.7 lib/chef/decorator/unchain.rb
chef-18.1.29 lib/chef/decorator/unchain.rb