summaryrefslogtreecommitdiff
path: root/lib/chef/resource_collection.rb
diff options
context:
space:
mode:
authortyler-ball <tyleraball@gmail.com>2014-10-17 08:30:53 -0500
committertyler-ball <tyleraball@gmail.com>2014-10-17 08:30:53 -0500
commit9323a77206955327fef2f17a42ca5e66c864cb26 (patch)
treea02afc15ce5340d5a10906e5d6868f4b26f12f0f /lib/chef/resource_collection.rb
parentb4adfb4cee189f2d3fdc534a24077269616cdd28 (diff)
downloadchef-9323a77206955327fef2f17a42ca5e66c864cb26.tar.gz
Cleaning up based on review comments
Diffstat (limited to 'lib/chef/resource_collection.rb')
-rw-r--r--lib/chef/resource_collection.rb25
1 files changed, 7 insertions, 18 deletions
diff --git a/lib/chef/resource_collection.rb b/lib/chef/resource_collection.rb
index 2e202bd6eb..8a02651d7d 100644
--- a/lib/chef/resource_collection.rb
+++ b/lib/chef/resource_collection.rb
@@ -21,6 +21,7 @@ require 'chef/resource_collection/resource_set'
require 'chef/resource_collection/resource_list'
require 'chef/resource_collection/resource_collection_serialization'
require 'chef/log'
+require 'forwardable'
##
# ResourceCollection currently handles two tasks:
@@ -29,6 +30,7 @@ require 'chef/log'
class Chef
class ResourceCollection
include ResourceCollectionSerialization
+ extend Forwardable
def initialize
@resource_set = ResourceSet.new
@@ -42,13 +44,13 @@ class Chef
# If you know the at_location but not the resource_type or instance_name, pass them in as nil
# 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.
- def insert(resource, resource_type=nil, instance_name=nil, at_location=nil)
+ def insert(resource, resource_type:nil, instance_name:nil, at_location:nil)
if at_location
@resource_list.insert_at(at_location, resource)
else
@resource_list.insert(resource)
end
- unless resource_type.nil? || instance_name.nil?
+ if !(resource_type.nil? && instance_name.nil?)
@resource_set.insert_as(resource, resource_type, instance_name)
else
@resource_set.insert_as(resource)
@@ -85,28 +87,15 @@ class Chef
# @deprecated
alias_method :push, :<<
- # Read-only methods are simple to proxy - doing that below
+ # Read-only methods are simple to delegate - doing that below
RESOURCE_LIST_METHODS = Enumerable.instance_methods +
[:iterator, :all_resources, :[], :each, :execute_each_resource, :each_index, :empty?] -
[:find] # find needs to run on the set
RESOURCE_SET_METHODS = [:lookup, :find, :resources, :keys, :validate_lookup_spec!]
- def method_missing(name, *args, &block)
- if RESOURCE_LIST_METHODS.include?(name)
- proxy = @resource_list
- elsif RESOURCE_SET_METHODS.include?(name)
- proxy = @resource_set
- else
- raise NoMethodError.new("ResourceCollection does not proxy `#{name}`", name, args)
- end
- if block
- proxy.send(name, *args, &block)
- else
- proxy.send(name, *args)
- end
-
- end
+ def_delegators :@resource_list, *RESOURCE_LIST_METHODS
+ def_delegators :@resource_set, *RESOURCE_SET_METHODS
end
end