Method: Chef::DSL::DeclareResource#edit_resource
- Defined in:
- lib/chef/dsl/declare_resource.rb
#edit_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block) ⇒ Chef::Resource
Lookup a resource in the resource collection by name. If it exists, return it. If it does not exist, create it. This is a useful function for accumulator patterns. In CRUD terminology this is an “upsert” operation and is used to assert that the resource must exist with the specified properties.
155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/chef/dsl/declare_resource.rb', line 155 def edit_resource(type, name, created_at: nil, run_context: self.run_context, &resource_attrs_block) edit_resource!(type, name, created_at: created_at, run_context: run_context, &resource_attrs_block) rescue Chef::Exceptions::ResourceNotFound resource = declare_resource(type, name, created_at: created_at, run_context: run_context) if resource_attrs_block if defined?(new_resource) resource.instance_exec(new_resource, &resource_attrs_block) else resource.instance_exec(&resource_attrs_block) end end resource end |