summaryrefslogtreecommitdiff
path: root/lib/chef/resource_collection
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-10-21 14:25:31 -0700
committerSerdar Sutay <serdar@opscode.com>2014-10-21 14:27:04 -0700
commit099b907a763cd9e531903f858eee0940c16248e2 (patch)
tree3e7987fa61610731c102a0b30784d638889aed93 /lib/chef/resource_collection
parentc038f2bf1a99c162073a9282567b137c7fa91201 (diff)
downloadchef-099b907a763cd9e531903f858eee0940c16248e2.tar.gz
Delegate Array methods rather than hardcoding into the ResourceList class.sersut/resource-list-specs
Diffstat (limited to 'lib/chef/resource_collection')
-rw-r--r--lib/chef/resource_collection/resource_list.rb29
1 files changed, 9 insertions, 20 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