Class: Chef::Node::AttrArray
- Inherits:
-
Array
- Object
- Array
- Chef::Node::AttrArray
- 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
- #<<(obj) ⇒ Object
- #delete(key, &block) ⇒ Object
- #dup ⇒ Object
-
#initialize(data = []) ⇒ AttrArray
constructor
A new instance of AttrArray.
-
#safe_dup(e) ⇒ Object
For elements like Fixnums, true, nil...
- #to_yaml(*opts) ⇒ Object
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.
60 61 62 63 |
# File 'lib/chef/node/attribute_collections.rb', line 60 def initialize(data = []) super(data) map! { |e| convert_value(e) } end |
Instance Method Details
#<<(obj) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/chef/node/attribute_collections.rb', line 48 def <<(obj) ret = super(obj) # NOTE: Expecting __path__ to be top-level attribute only send_reset_cache(__path__) ret end |
#delete(key, &block) ⇒ Object
55 56 57 58 |
# File 'lib/chef/node/attribute_collections.rb', line 55 def delete(key, &block) send_reset_cache(__path__, key) super end |
#dup ⇒ Object
72 73 74 |
# File 'lib/chef/node/attribute_collections.rb', line 72 def dup Array.new(map { |e| safe_dup(e) }) end |
#safe_dup(e) ⇒ Object
For elements like Fixnums, true, nil...
66 67 68 69 70 |
# File 'lib/chef/node/attribute_collections.rb', line 66 def safe_dup(e) e.dup rescue TypeError e end |
#to_yaml(*opts) ⇒ Object
76 77 78 |
# File 'lib/chef/node/attribute_collections.rb', line 76 def to_yaml(*opts) to_a.to_yaml(*opts) end |