Class: Chef::Node::AttrArray

Inherits:
Array
  • Object
show all
Includes:
Mixin::MashyArray, Mixin::StateTracking
Defined in:
lib/chef/node/attribute_collections.rb

Overview

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.

Constant Summary collapse

MUTATOR_METHODS =
Chef::Node::Mixin::ImmutablizeArray::DISALLOWED_MUTATOR_METHODS

Instance Attribute Summary

Attributes included from Mixin::StateTracking

#__node__, #__path__, #__precedence__, #__root__

Instance Method Summary collapse

Methods included from Mixin::MashyArray

#<<, #[]=, #collect!, #fill, #insert, #map!, #push, #replace, #unshift

Methods included from Mixin::StateTracking

#[], #[]=

Constructor Details

#initialize(data = []) ⇒ AttrArray

Returns a new instance of AttrArray.



52
53
54
55
# File 'lib/chef/node/attribute_collections.rb', line 52

def initialize(data = [])
  super(data)
  map! { |e| convert_value(e) }
end

Instance Method Details

#delete(key, &block) ⇒ Object



47
48
49
50
# File 'lib/chef/node/attribute_collections.rb', line 47

def delete(key, &block)
  send_reset_cache(__path__, key)
  super
end

#dupObject



64
65
66
# File 'lib/chef/node/attribute_collections.rb', line 64

def dup
  Array.new(map { |e| safe_dup(e) })
end

#safe_dup(e) ⇒ Object

For elements like Fixnums, true, nil…



58
59
60
61
62
# File 'lib/chef/node/attribute_collections.rb', line 58

def safe_dup(e)
  e.dup
rescue TypeError
  e
end

#to_yaml(*opts) ⇒ Object



68
69
70
# File 'lib/chef/node/attribute_collections.rb', line 68

def to_yaml(*opts)
  to_a.to_yaml(*opts)
end