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 more...
Defined Under Namespace
Modules: ResourceCollectionSerialization Classes: ResourceList, ResourceSet, StepableIterator
Instance Attribute Summary collapse
-
#run_context ⇒ Object
Returns the value of attribute run_context.
-
#unified_mode ⇒ Object
Returns the value of attribute unified_mode.
Class Method Summary collapse
Instance Method Summary collapse
- #[]=(index, resource) ⇒ Object deprecated Deprecated.
- #delete(key) ⇒ Object
- #find(*args) ⇒ Object
- #find_local(*args) ⇒ Object
-
#initialize(run_context = nil) ⇒ 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.
- #lookup(key) ⇒ Object
- #lookup_local(key) ⇒ Object
- #push(*resources) ⇒ Object deprecated Deprecated.
Methods included from ResourceCollectionSerialization
included, #is_chef_resource!, #to_h, #to_json
Constructor Details
permalink #initialize(run_context = nil) ⇒ ResourceCollection
Returns a new instance of ResourceCollection.
42 43 44 45 46 47 |
# File 'lib/chef/resource_collection.rb', line 42 def initialize(run_context = nil) @run_context = run_context @resource_set = ResourceSet.new @resource_list = ResourceList.new @unified_mode = false end |
Instance Attribute Details
permalink #run_context ⇒ Object
Returns the value of attribute run_context.
38 39 40 |
# File 'lib/chef/resource_collection.rb', line 38 def run_context @run_context end |
permalink #unified_mode ⇒ Object
Returns the value of attribute unified_mode.
35 36 37 |
# File 'lib/chef/resource_collection.rb', line 35 def unified_mode @unified_mode end |
Class Method Details
permalink .from_hash(o) ⇒ Object
[View source]
127 128 129 130 131 132 133 134 135 |
# File 'lib/chef/resource_collection.rb', line 127 def self.from_hash(o) collection = new { "@resource_list" => "ResourceList", "@resource_set" => "ResourceSet" }.each_pair do |name, klass| obj = Chef::ResourceCollection.const_get(klass).from_hash(o["instance_vars"].delete(name)) collection.instance_variable_set(name.to_sym, obj) end collection.instance_variable_set(:@run_context, o["instance_vars"].delete("@run_context")) collection end |
Instance Method Details
permalink #[]=(index, resource) ⇒ Object
Deprecated.
75 76 77 78 79 |
# File 'lib/chef/resource_collection.rb', line 75 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 |
permalink #delete(key) ⇒ Object
[View source]
68 69 70 71 72 |
# File 'lib/chef/resource_collection.rb', line 68 def delete(key) res = resource_set.delete(key) resource_list.delete(res.to_s) res end |
permalink #find(*args) ⇒ Object
[View source]
119 120 121 122 123 124 125 |
# File 'lib/chef/resource_collection.rb', line 119 def find(*args) if run_context.nil? find_local(*args) else find_recursive(run_context, *args) end end |
permalink #find_local(*args) ⇒ Object
[View source]
107 108 109 |
# File 'lib/chef/resource_collection.rb', line 107 def find_local(*args) resource_set.find(*args) end |
permalink #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.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/chef/resource_collection.rb', line 54 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 if unified_mode run_context.runner.run_all_actions(resource) end end |
permalink #lookup(key) ⇒ Object
[View source]
111 112 113 114 115 116 117 |
# File 'lib/chef/resource_collection.rb', line 111 def lookup(key) if run_context.nil? lookup_local(key) else lookup_recursive(run_context, key) end end |
permalink #lookup_local(key) ⇒ Object
[View source]
103 104 105 |
# File 'lib/chef/resource_collection.rb', line 103 def lookup_local(key) resource_set.lookup(key) end |
permalink #push(*resources) ⇒ Object
Deprecated.
82 83 84 85 86 87 88 |
# File 'lib/chef/resource_collection.rb', line 82 def push(*resources) Chef::Log.warn("`push` is deprecated, use `insert`") resources.flatten.each do |res| insert(res) end self end |