Class: Chef::Node::AttrArray

Inherits:
Array
  • Object
show all
Includes:
Mixin::MashyArray, Mixin::StateTrackingArray
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.



61
62
63
64
# File 'lib/chef/node/attribute_collections.rb', line 61

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

Instance Method Details

#<<(obj) ⇒ Object



49
50
51
52
53
54
# 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) ⇒ Object



56
57
58
59
# File 'lib/chef/node/attribute_collections.rb', line 56

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

#dupObject



73
74
75
# File 'lib/chef/node/attribute_collections.rb', line 73

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

#safe_dup(e) ⇒ Object

For elements like Fixnums, true, nil…



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

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

#to_yaml(*opts) ⇒ Object



77
78
79
# File 'lib/chef/node/attribute_collections.rb', line 77

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