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

Class Method Details

.included(base) ⇒ Object


40
41
42
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 40

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#is_chef_resource!(arg) ⇒ Object


58
59
60
61
62
63
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 58

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
  true
end

#to_hashObject

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_hash
  instance_vars = Hash.new
  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


36
37
38
# File 'lib/chef/resource_collection/resource_collection_serialization.rb', line 36

def to_json(*a)
  Chef::JSONCompat.to_json(to_hash, *a)
end