Module: Chef::ResourceCollection::ResourceCollectionSerialization
- Included in:
- Chef::ResourceCollection, ResourceList, ResourceSet
- Defined in:
- lib/chef/resource_collection/resource_collection_serialization.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #is_chef_resource!(arg) ⇒ Object
-
#to_h ⇒ Object
(also: #to_hash)
Serialize this object as a hash.
- #to_json(*a) ⇒ Object
Class Method Details
.included(base) ⇒ Object
42 43 44 |
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 42 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#is_chef_resource!(arg) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 60 def is_chef_resource!(arg) unless arg.is_a?(Chef::Resource) raise ArgumentError, "Cannot insert a #{arg.class} into a resource collection: must be a subclass of Chef::Resource" end true end |
#to_h ⇒ Object Also known as: to_hash
Serialize this object as a hash
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 25 def to_h instance_vars = {} instance_variables.each do |iv| instance_vars[iv] = instance_variable_get(iv) end { "json_class" => self.class.name, "instance_vars" => instance_vars, } end |
#to_json(*a) ⇒ Object
38 39 40 |
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 38 def to_json(*a) Chef::JSONCompat.to_json(to_hash, *a) end |