Class: Chef::ResourceCollection
- Inherits:
-
Object
- Object
- Chef::ResourceCollection
- Extended by:
- Forwardable
- Includes:
- ResourceCollectionSerialization
- Defined in:
- lib/chef/resource_collection.rb,
lib/chef/resource_collection/resource_set.rb,
lib/chef/resource_collection/resource_list.rb,
lib/chef/resource_collection/stepable_iterator.rb,
lib/chef/resource_collection/resource_collection_serialization.rb
Defined Under Namespace
Modules: ResourceCollectionSerialization Classes: ResourceList, ResourceSet, StepableIterator
Instance Method Summary collapse
- #[]=(index, resource) ⇒ Object deprecated Deprecated.
-
#initialize ⇒ ResourceCollection
constructor
A new instance of ResourceCollection.
-
#insert(resource, opts = {}) ⇒ Object
(also: #<<)
This method is meant to be the 1 insert method necessary in the future.
- #push(*resources) ⇒ Object deprecated Deprecated.
Methods included from ResourceCollectionSerialization
included, #is_chef_resource!, #to_hash, #to_json
Constructor Details
#initialize ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
38 39 40 41 |
# File 'lib/chef/resource_collection.rb', line 38 def initialize @resource_set = ResourceSet.new @resource_list = ResourceList.new end |
Instance Method Details
#[]=(index, resource) ⇒ Object
Deprecated.
60 61 62 63 64 |
# File 'lib/chef/resource_collection.rb', line 60 def []=(index, resource) Chef::Log.warn("`[]=` is deprecated, use `insert` (which only inserts at the end)") resource_list[index] = resource resource_set.insert_as(resource) end |
#insert(resource, opts = {}) ⇒ Object Also known as: <<
This method is meant to be the 1 insert method necessary in the future. It should support all known use cases
for writing into the ResourceCollection.
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/chef/resource_collection.rb', line 48 def insert(resource, opts = {}) resource_type ||= opts[:resource_type] # Would rather use Ruby 2.x syntax, but oh well instance_name ||= opts[:instance_name] resource_list.insert(resource) if !(resource_type.nil? && instance_name.nil?) resource_set.insert_as(resource, resource_type, instance_name) else resource_set.insert_as(resource) end end |