Class: Chef::Node::ImmutableArray
- 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
- #dup ⇒ Object
-
#initialize(array_data) ⇒ ImmutableArray
constructor
A new instance of ImmutableArray.
Methods included from 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
#dup ⇒ Object
88 89 90 |
# File 'lib/chef/node/immutable_collections.rb', line 88 def dup Array.new(map {|e| e.dup }) end |