diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-10-17 08:30:53 -0500 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-17 08:30:53 -0500 |
commit | 9323a77206955327fef2f17a42ca5e66c864cb26 (patch) | |
tree | a02afc15ce5340d5a10906e5d6868f4b26f12f0f /lib | |
parent | b4adfb4cee189f2d3fdc534a24077269616cdd28 (diff) | |
download | chef-9323a77206955327fef2f17a42ca5e66c864cb26.tar.gz |
Cleaning up based on review comments
Diffstat (limited to 'lib')
-rw-r--r-- | lib/chef/dsl/recipe.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource_collection.rb | 25 | ||||
-rw-r--r-- | lib/chef/resource_collection/resource_set.rb | 4 |
3 files changed, 11 insertions, 20 deletions
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb index b110371036..72de9e3662 100644 --- a/lib/chef/dsl/recipe.rb +++ b/lib/chef/dsl/recipe.rb @@ -86,7 +86,7 @@ class Chef resource = build_resource(type, name, created_at, &resource_attrs_block) - run_context.resource_collection.insert(resource, type, name) + run_context.resource_collection.insert(resource, resource_type:type, instance_name:name) resource end 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 diff --git a/lib/chef/resource_collection/resource_set.rb b/lib/chef/resource_collection/resource_set.rb index e3287951d7..6425c2ab08 100644 --- a/lib/chef/resource_collection/resource_set.rb +++ b/lib/chef/resource_collection/resource_set.rb @@ -40,8 +40,10 @@ class Chef @resources_by_key.keys end - def insert_as(resource, resource_type=resource.resource_name, instance_name=resource.name) + def insert_as(resource, resource_type=nil, instance_name=nil) is_chef_resource!(resource) + resource_type ||= resource.resource_name + instance_name ||= resource.name key = ResourceSet.create_key(resource_type, instance_name) @resources_by_key[key] = resource end |