Class: Chef::Node::AttrArray

Inherits:
Array
  • Object
show all
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 =
[
  :<<,
  :[]=,
  :clear,
  :collect!,
  :compact!,
  :default=,
  :default_proc=,
  :delete_at,
  :delete_if,
  :fill,
  :flatten!,
  :insert,
  :keep_if,
  :map!,
  :merge!,
  :pop,
  :push,
  :update,
  :reject!,
  :reverse!,
  :replace,
  :select!,
  :shift,
  :slice!,
  :sort!,
  :sort_by!,
  :uniq!,
  :unshift,
]

Instance Method Summary collapse

Constructor Details

#initialize(data = []) ⇒ AttrArray

Returns a new instance of AttrArray


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

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

Instance Method Details

#delete(key, &block) ⇒ Object


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

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

#dupObject


88
89
90
# File 'lib/chef/node/attribute_collections.rb', line 88

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

#safe_dup(e) ⇒ Object

For elements like Fixnums, true, nil...


82
83
84
85
86
# File 'lib/chef/node/attribute_collections.rb', line 82

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