summaryrefslogtreecommitdiff
path: root/lib/chef/resource_collection.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chef/resource_collection.rb')
-rw-r--r--lib/chef/resource_collection.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/chef/resource_collection.rb b/lib/chef/resource_collection.rb
index 5728fdd3e9..362781ea0e 100644
--- a/lib/chef/resource_collection.rb
+++ b/lib/chef/resource_collection.rb
@@ -111,6 +111,26 @@ class Chef
flat_results = results.flatten
flat_results.length == 1 ? flat_results[0] : flat_results
end
+
+ # Serialize this object as a hash
+ def to_json(*a)
+ instance_vars = Hash.new
+ self.instance_variables.each do |iv|
+ instance_vars[iv] = self.instance_variable_get(iv)
+ end
+ {
+ 'json_class' => self.class.name,
+ 'instance_vars' => instance_vars
+ }.to_json(*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)
+ end
+ collection
+ end
private