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
Source
# File lib/chef/node/immutable_collections.rb, line 79 def initialize(array_data = []) array_data.each do |value| internal_push(immutablize(value)) end end
Public Instance Methods
Source
# File lib/chef/node/immutable_collections.rb, line 92 def dup Array.new(map { |e| safe_dup(e) }) end
Source
# File lib/chef/node/immutable_collections.rb, line 86 def safe_dup(e) e.dup rescue TypeError e end
For elements like Fixnums, true, nil…
Source
# File lib/chef/node/immutable_collections.rb, line 96 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
Source
# File lib/chef/node/immutable_collections.rb, line 113 def to_yaml(*opts) to_a.to_yaml(*opts) end
As Psych module, not respecting ImmutableArray
object So first convert it to Hash/Array then parse it to ‘.to_yaml`
Private Instance Methods
Source
# File lib/chef/node/immutable_collections.rb, line 124 def [](*args) value = super value = value.call while value.is_a?(::Chef::DelayedEvaluator) value end
Calls superclass method
Source
# File lib/chef/node/immutable_collections.rb, line 120 def convert_key(key) key end
needed for __path__