class Chef::Node::AttrArray

AttrArray

AttrArray is identical to Array, except that it keeps a reference to the “root” (Chef::Node::Attribute) object, and will trigger a cache invalidation on that object when mutated.

Constants

MUTATOR_METHODS

Public Class Methods

new(data = []) click to toggle source
Calls superclass method
# File lib/chef/node/attribute_collections.rb, line 61
def initialize(data = [])
  super(data)
  map! { |e| convert_value(e) }
end

Public Instance Methods

<<(obj) click to toggle source
Calls superclass method Chef::Node::Mixin::MashyArray#<<
# File lib/chef/node/attribute_collections.rb, line 49
def <<(obj)
  ret = super(obj)
  # NOTE: Expecting __path__ to be top-level attribute only
  send_reset_cache(__path__)
  ret
end
delete(key, &block) click to toggle source
Calls superclass method
# File lib/chef/node/attribute_collections.rb, line 56
def delete(key, &block)
  send_reset_cache(__path__, key)
  super
end
dup() click to toggle source
# File lib/chef/node/attribute_collections.rb, line 73
def dup
  Array.new(map { |e| safe_dup(e) })
end
safe_dup(e) click to toggle source

For elements like Fixnums, true, nil…

# File lib/chef/node/attribute_collections.rb, line 67
def safe_dup(e)
  e.dup
rescue TypeError
  e
end
to_yaml(*opts) click to toggle source
# File lib/chef/node/attribute_collections.rb, line 77
def to_yaml(*opts)
  to_a.to_yaml(*opts)
end

Private Instance Methods

convert_key(key) click to toggle source

needed for __path__

# File lib/chef/node/attribute_collections.rb, line 97
def convert_key(key)
  key
end
convert_value(value) click to toggle source
# File lib/chef/node/attribute_collections.rb, line 83
def convert_value(value)
  case value
  when VividMash, AttrArray
    value
  when Hash
    VividMash.new(value, __root__, __node__, __precedence__)
  when Array
    AttrArray.new(value, __root__, __node__, __precedence__)
  else
    value
  end
end