summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/resource_collection/resource_list.rb29
-rw-r--r--spec/unit/resource_collection/resource_list_spec.rb2
2 files changed, 10 insertions, 21 deletions
diff --git a/lib/chef/resource_collection/resource_list.rb b/lib/chef/resource_collection/resource_list.rb
index edc65534e9..a26bd347aa 100644
--- a/lib/chef/resource_collection/resource_list.rb
+++ b/lib/chef/resource_collection/resource_list.rb
@@ -19,6 +19,7 @@
require 'chef/resource'
require 'chef/resource_collection/stepable_iterator'
require 'chef/resource_collection/resource_collection_serialization'
+require 'forwardable'
# This class keeps the list of all known Resources in the order they are to be executed in. It also keeps a pointer
# to the most recently executed resource so we can add resources-to-execute after this point.
@@ -27,9 +28,17 @@ class Chef
class ResourceList
include ResourceCollection::ResourceCollectionSerialization
include Enumerable
+ extend Forwardable
attr_reader :iterator
+ attr_reader :resources
+ private :resources
+ # Delegate direct access methods to the @resources array
+ # 4 extra methods here are not included in the Enumerable's instance methods
+ direct_access_methods = Enumerable.instance_methods + [ :[], :each, :each_index, :empty? ]
+ def_delegators :resources, *(direct_access_methods)
+
def initialize
@resources = Array.new
@insert_after_idx = nil
@@ -67,16 +76,6 @@ class Chef
@resources
end
- def [](index)
- @resources[index]
- end
-
- def each
- @resources.each do |resource|
- yield resource
- end
- end
-
def execute_each_resource(&resource_exec_block)
@iterator = ResourceCollection::StepableIterator.for_collection(@resources)
@iterator.each_with_index do |resource, idx|
@@ -85,16 +84,6 @@ class Chef
end
end
- def each_index
- @resources.each_index do |i|
- yield i
- end
- end
-
- def empty?
- @resources.empty?
- end
-
end
end
end
diff --git a/spec/unit/resource_collection/resource_list_spec.rb b/spec/unit/resource_collection/resource_list_spec.rb
index 2df98e3952..641fe55c8d 100644
--- a/spec/unit/resource_collection/resource_list_spec.rb
+++ b/spec/unit/resource_collection/resource_list_spec.rb
@@ -80,7 +80,7 @@ describe Chef::ResourceCollection::ResourceList do
current = 0
expected_resources = [resource, second_resource]
- resource_list.execute_each_resource do |r|
+ resource_list.each do |r|
expect(r).to be(expected_resources[current])
current += 1
end