Sha256: 9cc477974da321beac9407da347276934780632c511b7e238033af2673faf33f

Contents?: true

Size: 1.24 KB

Versions: 28

Compression:

Stored size: 1.24 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

28 entries across 28 versions & 1 rubygems

Version Path
chef-14.13.11-universal-mingw32 lib/chef/decorator/unchain.rb
chef-15.0.300-universal-mingw32 lib/chef/decorator/unchain.rb
chef-15.0.298-universal-mingw32 lib/chef/decorator/unchain.rb
chef-15.0.293-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.12.9-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.12.3-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.12.14-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.11.21-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.10.9-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.9.13-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.8.12-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.7.17-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.12.3-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.6.47-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.11.3-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.5.33-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.10.4-universal-mingw32 lib/chef/decorator/unchain.rb
chef-14.3.37-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.10.0-universal-mingw32 lib/chef/decorator/unchain.rb
chef-13.9.4-universal-mingw32 lib/chef/decorator/unchain.rb