class Chef::Node::ImmutableArray
ImmutableArray¶ ↑
ImmutableArray is used to implement Array collections when reading node attributes.
ImmutableArray acts like an ordinary Array, except:
-
Methods that mutate the array are overridden to raise an error, making the collection more or less immutable.
-
Since this class stores values computed from a parent Chef::Node::Attribute's values, it overrides all reader methods to detect staleness and raise an error if accessed when stale.
Public Class Methods
new(array_data = [])
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 67 def initialize(array_data = []) array_data.each do |value| internal_push(immutablize(value)) end end
Public Instance Methods
dup()
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 80 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/immutable_collections.rb, line 74 def safe_dup(e) e.dup rescue TypeError e end
to_a()
click to toggle source
# File lib/chef/node/immutable_collections.rb, line 84 def to_a Array.new(map do |v| case v when ImmutableArray v.to_a when ImmutableMash v.to_h else safe_dup(v) end end) end
Also aliased as: to_array
Private Instance Methods
convert_key(key)
click to toggle source
needed for __path__
# File lib/chef/node/immutable_collections.rb, line 102 def convert_key(key) key end