class Chef::Node::VividMash
VividMash
¶ ↑
VividMash
is identical to a Mash
, with a few exceptions:
-
It has a reference to the root
Chef::Node::Attribute
to which it belongs, and will trigger cache invalidation on that object when mutated. -
It auto-vivifies, that is a reference to a missing element will result in the creation of a new
VividMash
for that key. (This only works when using the element reference method, `[]` – other methods, such asfetch
, work as normal). -
attr_accessor style element set and get are supported via method_missing
Constants
Public Class Methods
Mash::new
# File lib/chef/node/attribute_collections.rb, line 126 def initialize(data = {}) super(data) end
Public Instance Methods
# File lib/chef/node/attribute_collections.rb, line 130 def [](key) value = super if !key?(key) value = self.class.new({}, __root__) self[key] = value else value end end
Mash#[]=
# File lib/chef/node/attribute_collections.rb, line 140 def []=(key, value) ret = super send_reset_cache(__path__, key) ret # rubocop:disable Lint/Void end
Mash#convert_key
# File lib/chef/node/attribute_collections.rb, line 148 def convert_key(key) super end
Mash
uses convert_value
to mashify values on input. We override it here to convert hash or array values to VividMash
or AttrArray
for consistency and to ensure that the added parts of the attribute tree will have the correct cache invalidation behavior.
# File lib/chef/node/attribute_collections.rb, line 156 def convert_value(value) case value when VividMash value when AttrArray value when Hash VividMash.new(value, __root__, __node__, __precedence__) when Array AttrArray.new(value, __root__, __node__, __precedence__) else value end end
Mash#delete
# File lib/chef/node/attribute_collections.rb, line 121 def delete(key, &block) send_reset_cache(__path__, key) super end
# File lib/chef/node/attribute_collections.rb, line 171 def dup Mash.new(self) end