diff options
author | tyler-ball <tyleraball@gmail.com> | 2014-10-16 10:07:40 -0500 |
---|---|---|
committer | tyler-ball <tyleraball@gmail.com> | 2014-10-16 10:33:02 -0500 |
commit | 72dd653d9481848a7489845a46851c66964c5a37 (patch) | |
tree | 82b3be7d0c343182ac9fc294459495ff2f70b911 /lib/chef/resource_collection | |
parent | 322eaf62464f306e2e3b3fec5b9fed15d17fc50b (diff) | |
download | chef-72dd653d9481848a7489845a46851c66964c5a37.tar.gz |
Refactoring ResourceCollection interface to be backwards compatiable, all specs continue to pass, removing ResourceSet and ResourceList from consumer knowledge
Diffstat (limited to 'lib/chef/resource_collection')
-rw-r--r-- | lib/chef/resource_collection/resource_collection_serialization.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/chef/resource_collection/resource_collection_serialization.rb b/lib/chef/resource_collection/resource_collection_serialization.rb index 708e72d848..8c11b9beeb 100644 --- a/lib/chef/resource_collection/resource_collection_serialization.rb +++ b/lib/chef/resource_collection/resource_collection_serialization.rb @@ -16,6 +16,7 @@ # limitations under the License. # class Chef + # TODO move into subfolder until we promote these to top level classes class ResourceCollection module ResourceCollectionSerialization # Serialize this object as a hash @@ -34,15 +35,21 @@ class Chef Chef::JSONCompat.to_json(to_hash, *a) end - def self.json_create(o) - collection = self.new() - o["instance_vars"].each do |k,v| - collection.instance_variable_set(k.to_sym, v) + def self.included(base) + base.extend(ClassMethods) + end + + module ClassMethods + def json_create(o) + collection = self.new() + o["instance_vars"].each do |k,v| + collection.instance_variable_set(k.to_sym, v) + end + collection end - collection end - def is_chef_resource(arg) + def is_chef_resource!(arg) unless arg.kind_of?(Chef::Resource) raise ArgumentError, "Cannot insert a #{arg.class} into a resource collection: must be a subclass of Chef::Resource" end |