class Chef::Node::ImmutableArray

ImmutableArray

ImmutableArray is used to implement Array collections when reading node attributes.

ImmutableArray acts like an ordinary Array, except:

Public Class Methods

new(array_data = []) click to toggle source
# File lib/chef/node/immutable_collections.rb, line 68
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 81
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 75
def safe_dup(e)
  e.dup
rescue TypeError
  e
end
to_a() click to toggle source
# File lib/chef/node/immutable_collections.rb, line 85
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
to_array()
Alias for: to_a
to_yaml(*opts) click to toggle source

As Psych module, not respecting ImmutableArray object So first convert it to Hash/Array then parse it to `.to_yaml`

# File lib/chef/node/immutable_collections.rb, line 102
def to_yaml(*opts)
  to_a.to_yaml(*opts)
end

Private Instance Methods

[](*args) click to toggle source
Calls superclass method
# File lib/chef/node/immutable_collections.rb, line 113
def [](*args)
  value = super
  value = value.call while value.is_a?(::Chef::DelayedEvaluator)
  value
end
convert_key(key) click to toggle source

needed for __path__

# File lib/chef/node/immutable_collections.rb, line 109
def convert_key(key)
  key
end