Method: Chef::ResourceCollection#insert

Defined in:
lib/chef/resource_collection.rb

#insert(resource) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chef/resource_collection.rb', line 57

def insert(resource)
  is_chef_resource(resource)
  if @insert_after_idx
    # in the middle of executing a run, so any resources inserted now should
    # be placed after the most recent addition done by the currently executing
    # resource
    @resources.insert(@insert_after_idx + 1, resource)
    # update name -> location mappings and register new resource
    @resources_by_name.each_key do |key|
      @resources_by_name[key] += 1 if @resources_by_name[key] > @insert_after_idx
    end
    @resources_by_name[resource.to_s] = @insert_after_idx + 1
    @insert_after_idx += 1
  else  
    @resources << resource
    @resources_by_name[resource.to_s] = @resources.length - 1
  end
end