Class: Chef::Node::ImmutableArray

Inherits:
Array
  • Object
show all
Includes:
Immutablize
Defined in:
lib/chef/node/immutable_collections.rb

Overview

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.

Constant Summary collapse

DISALLOWED_MUTATOR_METHODS =

A list of methods that mutate Array. Each of these is overridden to raise an error, making this instances of this class more or less immutable.

[
  :<<,
  :[]=,
  :clear,
  :collect!,
  :compact!,
  :default=,
  :default_proc=,
  :delete,
  :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

Methods included from Immutablize

#immutablize

Constructor Details

#initialize(array_data) ⇒ ImmutableArray

Returns a new instance of ImmutableArray.



69
70
71
72
73
# File 'lib/chef/node/immutable_collections.rb', line 69

def initialize(array_data)
  array_data.each do |value|
    internal_push(immutablize(value))
  end
end

Instance Method Details

#dupObject



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

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