Class: Chef::ResourceCollection

Inherits:
Object
  • Object
show all
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

Methods included from ResourceCollectionSerialization

included, #is_chef_resource!, #to_hash, #to_json

Constructor Details

#initializeResourceCollection

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.

Parameters:

  • resource (Chef::Resource)

    The resource to insert

  • resource_type (String, Symbol)

    If known, the resource type used in the recipe, Eg ‘package`, `execute`

  • instance_name (String)

    If known, the recource name as used in the recipe, IE ‘vim` in `package ’vim’‘



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

#push(*resources) ⇒ Object

Deprecated.


67
68
69
70
71
72
73
# File 'lib/chef/resource_collection.rb', line 67

def push(*resources)
  Chef::Log.warn("`push` is deprecated, use `insert`")
  resources.flatten.each do |res|
    insert(res)
  end
  self
end